NodeJS just strips TS types and prays that it runs as JS. It's not a native support by any means.
For example it doesn't support enums.
Bun and Deno do the real thing.
NodeJS just strips TS types and prays that it runs as JS. It's not a native support by any means.
For example it doesn't support enums.
Bun and Deno do the real thing.
"deno run" also just strips the types. The type checker is 'opt-in' now.
Don't know what Bun does though.
> prays that it runs
If you want to use TS stripping for your own project the typescript ecosystem makes it very easy to avoid using the wrong features. Just set erasableSyntaxOnly and verbatimModuleSyntax to true in your tsconfig.json and you will be warned when you're doing something node would not be able to handle. These days I find more code is being written to be stripping friendly than not, the incompatible stuff is of little importance besides enum for which you could resort to an as const object or a string union. I consider the presence of such things a smell, the TS dev team considers things like enums to have been a mistake, the goal of TS is to remain minimally divergent with JS outside of the type annotations.
Oh for real? I thought the latest versions ran actual typescript.
Well, it does technically in that to "run TypeScript" all you have to do is strip the types, and execute the remaining JavaScript. This is what Node does, but it doesn't do any typechecking. You can always include TypeScript as a dependency to do the actual type checking for you.
Deno from my understanding included a version of the TypeScript compiler as part of its build. Node doesn't do this. I'm not sure what Bun does, but I wouldn't trust it for anything more than a hobby project.