Live data from Hacker News

ts-blank-space is a fast type-stripping compiler

bloomberg.github.io

21–30 of 49 posts

Re: ts-blank-space is a fast type-stripping compiler

#21
post #19

Earlier quoted context omitted.

Lots of TypeScript features generate code: namespace, async/await, yield, decorators, object spread, varargs, etc.* `const enums` (beyond enums) are especially odd. They rely on type information to emit code. * Subsequent to their release in TypeScript, EcmaScript versions now support some of these.

So, since they're now a part of JS - aside from namespaces and enums (which are discouraged) - none of those features generate code anymore. Moreover, aside from namespaces and enums (which are discouraged), none of those features were incorporated into TypeScript until they were on track for inclusion into JS. They weren't taken from TypeScript and imported into JS; TypeScript took them from the ECMAScript people. B…

Decorators and decorator metadata.

> For better or for worse, the TypeScript team steadfastly refuses to try to innovate on runtime language features at this point.

Yes, largely because ECMAScript has advanced so far relatively to where it used to be.

Re: ts-blank-space is a fast type-stripping compiler

#22
post #17
post #13

I'm a little confused about when I'd use this, if I'm quickly iterating on code as I develop it, probably I also want to know whether it type checks, right?

TS language server will do that for you as go along

Wouldn't that defeat the point of what static typing affords you? Before you "go along"?

Re: ts-blank-space is a fast type-stripping compiler

#23
post #18

> We refer to the supported subset as Modern TypeScript because it represents nearly all TypeScript syntax, except for those TypeScript-specific features that may be considered legacy or discouraged in some way > These unsupported TypeScript features already have preferred alternatives: > Prefix-style type assertions ( value) should be replaced with as-style type assertions. Am I out of date? Does someone know someth…

What's not explained by the quoted excerpt? Instead of writing, e.g. `const n = someValueThatYouKnowIsANumber;`, you should write `const n = someValueThatYouKnowIsANumber as number;` (well, really, you shouldn't write either, casts are bad. But, yknow.)

I mean I have not seen anything to suggest that angle brackets are "legacy or discouraged"

Re: ts-blank-space is a fast type-stripping compiler

#24
Or maybe just use jsdoc at this point and skip the compile step completely. Though i admit it is not as pretty to read but you can get used to it.

Still a nifty new tool though. I wish JS would just allow type declarations at this point. It doesn't need to enforce them, just allow them like Python does. That would be amazing.

Re: ts-blank-space is a fast type-stripping compiler

#25
post #22
post #17

Earlier quoted context omitted.

TS language server will do that for you as go along

Wouldn't that defeat the point of what static typing affords you? Before you "go along"?

No, during development your IDE will show you type errors and your dev server can ignore them. In CI tsc can type check. It's the best of all worlds: incorrect code will compile and work best-effort, you can see errors in your IDE, and CI will fail if it's incorrect.

Re: ts-blank-space is a fast type-stripping compiler

#26

I wish enum was never part of TypeScript. It’s this one odd thing unlike the rest. Am I forgetting any or is it the only feature that actually generates code rather than just being extra annotation?

Here's a good video about TS enums: https://www.youtube.com/watch?v=jjMbPt_H3RQ

Re: ts-blank-space is a fast type-stripping compiler

#27
post #18

Earlier quoted context omitted.

What's not explained by the quoted excerpt? Instead of writing, e.g. `const n = someValueThatYouKnowIsANumber;`, you should write `const n = someValueThatYouKnowIsANumber as number;` (well, really, you shouldn't write either, casts are bad. But, yknow.)

I mean I have not seen anything to suggest that angle brackets are "legacy or discouraged"

They're discouraged because they conflict with JSX. For instance, in the eslint documentation:

> Most codebases will want to enforce not using angle-bracket style because it conflicts with JSX syntax, and is confusing when paired with generic syntax.

https://typescript-eslint.io/rules/consistent-type-assertion...

Re: ts-blank-space is a fast type-stripping compiler

#28
post #2

You'd already be using source maps in any real-world scenario so I am not sure what's the value proposition here outside of "just for fun, I guess". The tsc transpilation to lower ES versions is actually really useful when using not-so-recent Node versions. Not to mention this severely restricts TypeScript syntax to "just types" which isn't too bad but it means you now have to worry about yet another thing. Then ther…

> You'd already be using source maps in any real-world scenario

We're shipping production real-time genomics apps in vanilla JS with no source maps.

Re: ts-blank-space is a fast type-stripping compiler

#29

Or maybe just use jsdoc at this point and skip the compile step completely. Though i admit it is not as pretty to read but you can get used to it. Still a nifty new tool though. I wish JS would just allow type declarations at this point. It doesn't need to enforce them, just allow them like Python does. That would be amazing.

At least Node.js has added experimental support that seems to do that: https://github.com/nodejs/node/pull/53725

But this is just an on-the-fly transpile(natively supported). It would be much better if JavaScript would go the Python route. For that they would have to extend the EcmaScript spec (to be safe) I guess.

Just using JSDoc is imho not a good alternative. The big benefit of TypeScript is that your compiler checks this all for you. I've seen to much incomplete or wrong JSDoc in my life.. also a nightmare to maintain.

Post reply on HN