- TypeScript version: >=3.5.1
- ECMAScript target version: ES2019
Because we would like to have
- TypeScript native libraries instead of using '@types'
- functional style libraries
- functions without side-effects
- immutable data
- Target the the latest ES standard and use the latest TS & ES features such as asynchronous iterators.
- https://standardjs.com/rules.html
- Conventions over configuration
- No sequential coupling. See https://en.wikipedia.org/wiki/Sequential_coupling
- No object inheritance. Use
- composition,
- unions, or
- discriminated unions
- No
any
type, useunknonw
instead - Use read only types.
readonly T[]
instead ofT[]
,readonly [A, B]
instead of[A, B]
,readonly
properties.
- No
var
. Useconst
instead. In some cases, uselet
. - No
export class
. Useexport interface
andexport function
instead. - No
null
. Useundefined
instead. - String index property type should be a superset of
undefined
.- Incorrect
{ [key: string]: T }
- Correct
{ [key: string]: undefined|T }
- Incorrect
- No
lodash
.. Use native lazy TypeScript libraries (such asts-common/iterator
) orlazy.js
. - No
throw
. Alternatives- return errors,
- use callback function (dependency injection).
- No
clone
,cloneDeep
. Use immutable data to avoid cloning. - No
Symbol("...")
. UseSymbol.for("...")
instead. - No
{ function(); }
declaration in the interface. Use{ readonly property: () => void }
instead. - No
as
operator. Use type narrowing. - No
is
operator. Use discriminators.
npm init
npm install -D typescript @types/jest jest jest-junit tslint tslint-immutable
package.json
:"scripts": { "tsc": "tsc", "test": "tsc && tslint -p tsconfig.json && jest", "prepack": "npm install && tsc" }, "jest": { "testEnvironment": "node", "testMatch": [ "**/dist/test/*test.js" ], "reporters": [ "jest-junit", "default" ], "collectCoverage": true, "collectCoverageFrom": [ "dist/*.js"], "coverageThreshold": { "global": { "branches": 100, "functions": 100, "lines": 100, "statements": 100 } }, "coveragePathIgnorePatterns": [ "/dist/test/" ], "coverageReporters": [ "cobertura", "text", "html" ] }, "jest-junit": { "outputDirectory": ".", "outputName": "test-results.xml" }, "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist/index.d.ts", "dist/index.d.ts.map", "dist/index.js.map", "dist/index.js", "src/index.ts" ],
npm run tsc -- --init
- tsconfig.json
- Create
src/index.ts
.gitignore
:*.js *.d.ts *.map test-results.xml
- azure-pipelines.yml
- tslint.json
- Save the Visual Studio Code workspace.