logoalt Hacker News

Cthulhu_today at 12:40 PM1 replyview on HN

In theory, typescript doesn't need to be transpiled, you can run ts files using `node --experimental-strip-types file.ts` as long as you don't use any code that needs transpilation (like typescript enums).

Still need tsx to do type checking


Replies

ivanjermakovtoday at 12:49 PM

No, because of ESM import resolution rules. Typescript suggests extensionless imports, making it incompartible with ESM and therefore Node. Luckly, `node --import=tsx file.ts` handles imports well.

This is especially hairy when making a typescript library that is distributed non-compiled (without dist/) and is supposed to run in both browser and Node.

https://github.com/nodejs/node/issues/46006

https://github.com/microsoft/TypeScript/issues/16577

show 2 replies