Erasable syntax — what Node can strip, and the features it cannot¶
Level: 201 · for TypeScript users running code under Node
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 runs TypeScript by overwriting type syntax with spaces and stops with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX at enum, parameter properties, a namespace holding values, import x = require() and the old <number>x assertion; erasableSyntaxOnly makes tsc report each as TS1294.
Keywords: erasableSyntaxOnly, ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, --experimental-transform-types
What the finished page will answer¶
- Which five constructs make Node stop with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, and what message does it give for each?
- What JavaScript would
tschave to write for anenumor a parameter property, and why can blanking out characters not produce it? - What does
erasableSyntaxOnlyreport for the same files, and why does this library'stsconfig.jsonturn it on? - Which look-alikes are still erasable: a
namespacethat holds only types, adeclare enum, anabstractclass, aprivate readonlyfield? - What does
--experimental-transform-typeschange, and what does it write to stderr? - What erasable replacement exists for each refused construct: an
as constobject for anenum, a field and an assignment for a parameter property,asfor<T>x?
Examples it will need¶
-
erasable_syntax_refused_sh.sh— Node's ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX message for each of five one-line files, then tsc's TS1294 for the same files under--erasableSyntaxOnly -
erasable_syntax_look_alikes_ts.ts— output from an abstract class, aprivate readonlyfield and a namespace that holds only types, all of which Node strips without complaint -
erasable_syntax_enum_tserror.ts— tsc's TS1294 for anenumunder the library's tsconfig
See also¶
- Types are erased — how the blanking works for everything Node does accept
- Enums — the enum, and the erasable object that replaces it
- Parameter properties — the constructor shorthand Node cannot strip
- Type-only imports —
import type, the other thing stripping needs spelled out satisfies,asand annotations — theasform of an assertion, which Node accepts