Live data from Hacker News

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

bloomberg.github.io

31–40 of 49 posts

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

#31
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 almost always want to export in both formats

I haven’t exported CJS in half a decade. I haven’t authored CJS in a decade. You most definitely do not always want to do that.

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

#32
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"

I don’t think I’ve seen a single codebase using that pattern ever. With React being so popular and TS growing in popularity just about after React, people have settled on `as` assertions instead, whether they use JSX or not.

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

#35

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.

This feels like the sort of thing that would be nice to have ide support for.

Open a js file with ts comments, and it silently converts to ts editing. Save the file and it converts ts back to js with comments before actually writing.

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

#36

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.

There is a proposal for that: https://github.com/tc39/proposal-type-annotations

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

#37
post #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.

Why?

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

#38
post #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 ch…

https://www.typescriptlang.org/docs/handbook/jsdoc-supported...

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

#39

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?

Strong disagree. enums + unions = ADTs. Without enums you have to use either string or number.

The problem with using strings is that nothing else uses strings (like say, your database), so you have to have this interminable roundtrip conversion between strings and integers.

JS programmers are in a bit of a bubble where using strings as enums is socially acceptable, if a C programmer saw this code

    typedef struct {
        const char* type;
    } Animal;
they would yell at you.

If a database engineer saw this schema:

    CREATE TABLE animal (
      id INTEGER PRIMARY KEY,
      type TEXT
    )
they would yell at you.

It's way nicer to use integer enums from A to Z, because everything else has enums and people use them.

If you use plain integers instead of integer enums then the compiler has no visibility into what your tags are. So your diagnostics will be hard to read because the compiler doesn't know that 69 is AnimalType.frog

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

#40
post #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 ch…

You can shove @ts-check on the top of js files and get some decent checks going on. It isn't 100% but it'll be pretty darn good.
Post reply on HN