Live data from Hacker News

Node.js is able to execute TypeScript files without additional configuration

nodejs.org

31–40 of 275 posts

Re: Node.js is able to execute TypeScript files without additional configuration

#33
post #17
post #2

It looks like this works by stripping away the type information, so at best it saves you a transpilation pass and doesn't improve safety.

TypeScript never promised improving safety, maybe it’s a common misconception. But TypeScript has no runtime mode or information. You were always at the mercy of running and not ignoring the typechecker. Nothing stopped you from running ts-node or tsx on code with egregious type errors. TypeScript is more like a linter in that regard.

I think it's not fair to say that Typescript isn't about improving safety, just that the mechanism isn't the same as with other languages. Typescript had always allowed you to ignore the type checker (in fact, the default configuration will always attempt to emit compiled Javascript, even if the source Typescript has type errors). But if you run the type checker on every commit (via e.g. CI or a precommit hook), then you can be sure that the code you release is correctly typed, which will not guarantee it is safe, but makes it more likely.

I agree that it's better to think of Typescript as a linter that needs specialised annotations to work, rather than a type system like you might find in Java or Rust.

Re: Node.js is able to execute TypeScript files without additional configuration

#34
post #17
post #2

It looks like this works by stripping away the type information, so at best it saves you a transpilation pass and doesn't improve safety.

TypeScript never promised improving safety, maybe it’s a common misconception. But TypeScript has no runtime mode or information. You were always at the mercy of running and not ignoring the typechecker. Nothing stopped you from running ts-node or tsx on code with egregious type errors. TypeScript is more like a linter in that regard.

> TypeScript is more like a linter

that's exactly the point--GP is pointing out that node can't do that part

Re: Node.js is able to execute TypeScript files without additional configuration

#35
post #29
post #20

Earlier quoted context omitted.

One of Typescript's design goals is that removing all type-related parts of the source text should yield a valid JavaScript file. A typescript compiler does not generate code (unlike, say, PureScript). You can run a typechecker (such as tsc) that check various properties of your code statically, relying on the type information. It is then erased. The same applies, say, to Python: type annotations are ignored at runti…

> A typescript compiler does not generate code Except for where it does: Enums, namespaces, parameter properties, etc.

Just use erasableSyntaxOnly = true and you're fine.

Re: Node.js is able to execute TypeScript files without additional configuration

#37
post #29
post #20

Earlier quoted context omitted.

One of Typescript's design goals is that removing all type-related parts of the source text should yield a valid JavaScript file. A typescript compiler does not generate code (unlike, say, PureScript). You can run a typechecker (such as tsc) that check various properties of your code statically, relying on the type information. It is then erased. The same applies, say, to Python: type annotations are ignored at runti…

> A typescript compiler does not generate code Except for where it does: Enums, namespaces, parameter properties, etc.

This is true but these are also old features, and the TS team have stated that they will not add any more features like those, and to a certain extent regret adding them initially (particularly decorators, which iirc were added because the Angular framework wanted to use them). You can also see that these features aren't really being updated to match recent Typescript developments (parameter properties can't do true private properties, const enums don't work with isolated modules, etc).

I don't think those features are ever going to go away, because they've been around for so long and are so widely used. But I generally use erasableSyntaxOnly in new projects, because I find it's useful when my typescript source matches the generated Javascript code as much as possible.

Re: Node.js is able to execute TypeScript files without additional configuration

#39
post #25

Earlier quoted context omitted.

This has nothing to do with the "node world". Such an enormous feature would have to go into ECMAScript. Which is very, very unlikely to ever happen, they may as well design a new language. All those runtimes implement that spec. Expecting them to write an extremely complex new feature that is easily more complicated than everything already implemented (especially with backwards compatibility, and given that the lang…

Can't be too hard imo. Primitives can contain an extra metadata field for the types defined in the code. This doesn't really interfere with the runtime and will be backwards compatible. The runtime of course still doesn't actually have to do any type checking, it's just forwarding the type information on a new metadata field so it's not in any way interrupting the core flow of the runtime logic. As a result you can s…

[dead]
Post reply on HN