About
About
Is a superset of Javascript empowering it by:
Static typing
Decorators
Generic types
Tuples
Modules
Better OO support with abstract classes
Interfaces
Visibility modifiers
And more...
Needs to be transpiled to Javascript.
Compiler: Transforms code to low code (machine-code).Transpiler: Transforms code to other high level languages (source-to-source).
Interoperability
Run js and ts in the same environment.
You can allow js to apply Typescript by creating a .d.ts file for a js file.
This file will have definitions typings for the js.
Exploring the tsconfig.json
tsconfig.jsonCentralizes all the code static analysis and transpilation rules.
Options
incremental: For incremental transpilation, saving cache that will speedup future transpilations, specially for big projects. Essentialy just transpile the changed files.target: Defines the version of Javascript that will be utilized as the transpilation target.es5 | ECMA2009: Older version from 2009.es6 | ECMA2015: Which targets the ECMA from 2015.ECMA2016: Is the default one. (Higher compatibility)Adds
**exponential, ...
ECMA2017:Adds
async, ...
ECMA2018:Adds
rest \ spread, ...
ECMA2019:ECMA2020:Adds
??
...
Check https://node.green/ for details of ECMA versions support in Node.js
Node 16.x and greater versions, do support up to ECMA2023.
ESNext is the versions with
Stage 3,Stage 2andStage 1releases
module: Important to define the type ofmodulesystem to be used. -CommonJS-ES Modulesinclude: Defines which are the directories that must be included in the transpilation.exclude: Defines which directores must be excluded in transpilation.outFile: Used for projects that run in the browser, defining a file that will concatenate all the transpiled files.outDir: Defines the directory that the transpiled files will be placed after transpilation.allowJS: To allow js files to part of the typescript environment.strict: Turn on several type checkings like:strictNullChecks: Allow or not to accept if things returnnull | undefinedand what will receive them cannot handle it.strictFunctionTypes: Allow or not to scrictly compare functions types to the detail when assigning functions to variables.strictBindCallApply: Allow of not to pass tofn.call(), parameters to the function that are not of the same type.strictPropertyInitialization: Allow or not to have class properties to be declared but not initialized.noImplicitAny: Allow or not using variables without typing, that can be automatically impliced typed.noImplicitThis: Allow or not, when you havethiscases, where thethisis not pointing to where you think it is.useUnknowInCatchVariables: Allow or not to use unknown error types in catch.alwaysStrict: Will always putuse strictin the transpiled file.Not used anymore in recent versions of ECMA.
allowUnreachableCode: Allow or not leaving code that is unreachable.noUnusedLocals: Allow or not leaving unused declared variables.noUncheckedIndexedAccess: Allow or not to access dynamic properties of objects with..For Ex.:
[prop: string]: string.The right way to access woulb be with
[].
Last updated