Skip to content

Running TypeScript — Node strips the types, tsc checks them

Level: 101 · for anyone about to run their first .ts file

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.

One line: node server.ts blanks out the types and runs, so a file that assigns "8080" to a number prints 80801 and exits 0; the check is a separate command, tsc --noEmit, which reports TS2322, writes nothing and exits 1.

Keywords: --no-strip-types, process.features.typescript, noEmit

What the finished page will answer

  • What does node server.ts print when port: number holds "8080", and what do tsc --noEmit and its exit status say about the same file?
  • Which Node versions strip types without a flag, what does process.features.typescript report, and what error does a typed file give under --no-strip-types?
  • What exit status does tsc give when it finds errors under --noEmit, and when it writes JavaScript despite them?
  • How does Node decide whether a .ts file is an ES module or CommonJS, and what do .mts and .cts change?
  • Why must a relative import say ./util.ts, and which tsconfig.json option lets tsc accept that?
  • What does Node do with a .ts file inside node_modules, and what does node --check app.ts report?

Examples it will need

  • running_typescript_both_commands_sh.sh — Node's 80801 and exit status 0 for a file with a type error, then tsc's TS2322 and exit status 1 for the same file
  • running_typescript_features_sh.sh — process.features.typescript with and without --no-strip-types, and the SyntaxError Node gives a typed file when stripping is off

See also

Sources to start from