Typescript makes Javascript strongly typed, for writing code that is more maintainable and fewer bugs. By declaring the type of value expected for variables, your IDE can catch issues and any errors thrown will be more clear.
Typescript code has a .ts extension, or .tsx for jsx code.
tsconfig.json
Configure compiler options.
Used when running tsc.
See also jsconfig.json (What's the difference?).
.ts file extension.
https://www.typescriptlang.org/tsconfig/
@alias
Set up aliases to reference code in your app.
JS/TS/ESM/Compatibility
What is the difference between these?
- Lib
- module - the module system (esm/cjs)
- what's the difference between ESNext and NodeNext?
- node16 == nodenext
- es2022 == esnext (top level await)
- what's the difference between ESNext and NodeNext?
- Target
- https://www.typescriptlang.org/tsconfig/#target
- Compatibility target?
- ES6 recommended for most browsers.
- moduleResolution
- Algorithm for resolving modules.
- Is this for imports or output?
- "bundler" - doesn't require file extensions
- Algorithm for resolving modules.
- esModuleInterop
- moduleDetection
https://www.typescriptlang.org/docs/handbook/modules/reference.html
https://www.typescriptlang.org/docs/handbook/modules/theory.html#the-module-output-format
https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html
https://www.typescriptlang.org/docs/handbook/modules/reference.html#nod…
Base configuration files
Baseline compatibility, IE Node16.
Recommended starting config.
https://github.com/tsconfig/bases
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#tsconfig-bases
ts-node
Run typescript natively, without compiling.
https://typestrong.org/ts-node/
https://www.npmjs.com/package/ts-node
I could not get ts-node to work with ESM Typescript modules. I had to use node --loader ts-node/esm.
Run scripts that use typescript code
I have a nextjs app that uses typescript. I would like to write scripts that import libraries written in TS and run on the command line.
node --loader ts-node/esm -r tsconfig-paths/register scripts/my-script.js
Documentation
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html