Typescript

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?

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

Level