Live data from Hacker News

TypeScript Without Transpilation (2021)

incrementalelm.com

11–20 of 46 posts

Re: TypeScript Without Transpilation (2021)

#11

JSDoc can get you pretty far, but it can be clumsy sometimes. There’s a [TC39 proposal]( https://github.com/tc39/proposal-type-annotations ) to allow types to live in JS code and be treated as comments (similar with Python types today)

Could that improve execution performance?

Re: TypeScript Without Transpilation (2021)

#12

JSDoc can get you pretty far, but it can be clumsy sometimes. There’s a [TC39 proposal]( https://github.com/tc39/proposal-type-annotations ) to allow types to live in JS code and be treated as comments (similar with Python types today)

Could that improve execution performance?

AFAIK that's not a goal for this proposal.

Re: TypeScript Without Transpilation (2021)

#14
I'm using this setup at the moment, mostly because I work on legacy code base that has no good types yet.

Typically you would do jsconfig.json though, which is same as tsconfig.json but allowJs is already set. Mostly stylistic change, but some tooling might benefit for having jsconfig instead of tsconfig.

Re: TypeScript Without Transpilation (2021)

#15

JSDoc can get you pretty far, but it can be clumsy sometimes. There’s a [TC39 proposal]( https://github.com/tc39/proposal-type-annotations ) to allow types to live in JS code and be treated as comments (similar with Python types today)

Could that improve execution performance?

No. First paragraph of the proposal:

> This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type checker that is external to JavaScript. At runtime, a JavaScript engine ignores them, treating the types as comments.

The problem is handling errors. If the engine does a full analysis of every code path to ensure the types aren't violated, there's a startup penalty - this includes every time a dynamic import is used, which could interfere with the user as they interact with the page. I'm not entirely sure that such an analysis would be entirely possible- there are many ways to add layers of indirection to JavaScript code.

If the engine doesn't do a full analysis up front but instead checks every time a type is used, you end up with, at best, roughly the same performance characteristics that current JIT engines already have.

Re: TypeScript Without Transpilation (2021)

#18

JSDoc can get you pretty far, but it can be clumsy sometimes. There’s a [TC39 proposal]( https://github.com/tc39/proposal-type-annotations ) to allow types to live in JS code and be treated as comments (similar with Python types today)

Could that improve execution performance?

Runtime type checks usually decrease the performance.
Post reply on HN