title | author |
---|---|
Utility Without the Clutter - Types Without TypeScript |
Nico Rehwaldt |
A Talk by @nikku
- Safety during development
- Guards against dependencies
- Editor tooling / advanced assistance
- Easier consumption for your users ⬆️
tsc
, the TypeScript tool
- Checks your code base
- Transpiles your TypeScript to JavaScript
- Generates types from your JavaScript
- Need to write
code.ts
- Everything has to be transpiled
- Source maps bloat packages and are hard to debug
- My code base is checked
- My code base is typed (for consumers)
.
├── src
│ ├── index.js
│ └── other.js
├── package.json
├── rollup.config.js
└── tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"strict": false,
"skipLibCheck": true,
...
},
...
}
/**
* @constructor
* @param { { sayHello: boolean } } options
*/
export function Foo(options) {
...
}
/**
* @typedef { import('./types').FooOptions } FooOptions
*/
/**
* @constructor
* @param { FooOptions } options
*/
export function Foo(options) {
...
}
tsc --noEmit --pretty
tsc src/index.js \
--declaration \
--emitDeclarationOnly \
--removeComments \
--outDir dist/types
{
"name": "my-project",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
...
}
import {
Foo
} from 'my-project';
const foo = new Foo({});
^---- Argument of type '{}' is not assignable to
parameter of type '{ sayHello: boolean }'.
- Haz types without
.ts
🍰 :medal: tsc
tooling helps you out 💪
- TypeScript Documentation - On JS projects utilizing TypeScript
- Skaat, Wuffle, merge-me - Projects that follow the types without TypeScript approach
👏