austingil.com | @heyAustinGil
I work at Akamai (akamai.com)
We offer a lot of relevant services
Really hard not to mention (kind of my job)
Impossible to be 100% unbiased
austingil.com | @heyAustinGil
I work at Akamai (akamai.com)
We offer a lot of relevant services
Really hard not to mention (kind of my job)
Impossible to be 100% unbiased
This is not a sales pitch in disguise
Iām here to teach practical, general concepts
I may mention Akamai because itās familiar
But this info applies anywhere



const input = document.querySelector('input')
const someVal = 100 / input.value
// @ts-check



// settings.json
{
// ...
"js/ts.implicitProjectConfig.checkJs": true,
}// tsconfig.json
{
"compilerOptions": {
"checkJs": true,
}
}npm install --save-dev typescript
// package.json
{
"scripts": {
"ts": "tsc"
}
}// tsconfig.json
{
"files": ["./src/index.js"],
"compilerOptions": {
"checkJs": true,
"allowJs": true,
"noEmit": true,
}
}npm run ts

pre-commit, pre-push)TS can use both .js or .ts files
JSDocs can work as a stepping stone
Or you can keep using JSDocs
(highly subjective)
(+ TypeScript)




.d.ts filesexport interface Dog {
breed: string
age: number
name?: string
}// @ts-ignore above line: Disable TS on that line.// @ts-nocheck top of file: Disable TS on whole file.exclude in tsconfig.json: Disable TS on groups of files.TypeScript mostly understands JSDocs, but not everything.
OK in TS
const canvas1 =
document.querySelector("canvas") as HTMLCanvasElement;
const canvas2 =
<HTMLCanvasElement>document.querySelector("canvas");Flat-out gross in JSDocs š¤®
const canvas1 = /** @type {HTMLCanvasElement} */ (
document.querySelector("canvas")
);.d.ts files and the CLI"My position is, types are fantastic, TypeScript is a bit of a pain ⦠as soon as you use a .ts file, then you have to have the tooling to support that ⦠thereās all of these points of friction when you use a non-standard language like TypeScript that I have come to believe makes it not worth it." - Rich Harris
"Like to keep the source I author the same as the source at runtime because debugging is way faster when it isnāt a murder mystery." - @brianleroux
"verbose comment - terse code" - @myfonj
/**
* @param {string} p1 - String param.
* @param {string=} p2 - Optional param (Closure syntax)
* @param {string} [p3] - Optional param (JSDoc syntax).
* @param {string} [p4="test"] - Param with default value.
* @return {string} This is the result
*/
function stringsStringStrings(p1, p2, p3, p4="test") {
// TODO
}function stringsStringStrings(
p1: string,
p2? : string,
p3?: string,
p4 = "test"
): string {
// TODO
}Read the blog post: austingil.com/typescript-the-easy-way