In this workshop, we will learn the power of types in TypeScript, and then use that power responsibly to create our own strongly typed functional library.
- Visual Studio Code
- When prompted, install recommended extensions
- Run
npm i
EcmaScript 5 and newer versions already have quite a few functional operators as part of the language.
These are all automatically typed as part of the TypeScript built-in typings; for example, try the following:
const values = [1, 2, 3]
const strings = values.map(x => 'string' * 1)
What is the type of strings?
That's right, string[]
!
To explore the typings of these, Ctrl+Click .map
, and you will see the content of node_modules/typescript/lib/lib.es5.d.ts
. This file and others in the same folder are the built-in typings of TypeScript, and can be used as a reference for best practice when writing your own types.
Do this part OR part 2b.
- Open
fs-lib.ts
andfs-lib.spec.ts
npm run test:fs-lib
- Implement till test works
- Extend with your own favourite functional functions
- Open
lodash-es.d.ts
andlodash-es.spec.ts
npm run test:lodash
- Write typings till they are as expected
- Extend with your own favourite lodash functions
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/fp.d.ts https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash/common
Check out https://gcanti.github.io/fp-ts/
Follow this tutorial series: https://dev.to/gcanti/getting-started-with-fp-ts-setoid-39f3
GitHub issue tracking full monad support in TypeScript Article about FP in JS Maybe in TypeScript