TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.86k stars 536 forks source link

Behavior of typescript compiler modified by ts-node #2045

Closed lengors closed 11 months ago

lengors commented 1 year ago

Search Terms

Expected Behavior

Typescript transpile behavior should not be modified when running the typescript compiler, but it is. As an example, if I set target compiler option of the typescript to ES5 and use some functionality from Symbols, the compiler will fail to compile if I do not have ts-node installed, but if I do it compiles succesfully.

Actual Behavior

Typescript compiler behavior should not change with ts-node installed. If I want to target a different language version for ts-node the option should be set in ts-node object inside the tsconfig.json file, but not change the behavior of the typescript compiler.

Steps to reproduce the problem

Minimal reproduction

https://github.com/lengors/ts-node-repro

Specifications

lengors commented 11 months ago

Found the problem. Since ts-node gets installed with @types/node, by not explicitily defining the compilerOptions.types property in the tsconfig.json, TypeScript automatically uses all packages in @types as packages to be included without being referenced in the source file and since @types/node has types from multiple JavaScript language versions, than those get automatically available even if we define an older version as taget. By explicitily setting the compilerOptions.types property, the issue goes away.