Hacker News new | ask | show | jobs
by schwartzworld 1425 days ago
I think OP means that if your project / job doesn't support typescript, you can write .ts files on your local machine and then compile them to .js. I think it would be very challenging though to be the only person on a project using TS though.
1 comments

Yeah that would be weird.

Using tsc to type check javascript - with JSDoc type annotations - works fine. You're really not missing much from "real" typescript, and you can save yourself a transpile.

It doesn't really work fine beyond a single file.

I tried the experiment of .js files driven by typescript in JSDocs for around 10k lines and there is a night and day difference in what you can express, how and reuse it at the type level.

I'm experienced in doing this too.

Name one thing you can't do.

To clairfy, if I am sharing types between modules I tend to use .d.ts files. Still no transpiling needed.

until you need to type the shape of objects, and want to share that shape with other files. You can't import JSDoc types from other files. At which point, you would be forced to create `types.d.ts` file or similar. Might as well be writing typescript.

The limitations are too much for complex projects at scale. I strongly believe this is why Closure types didn't take off.

That and Google's lack of developer relations around the project

You can use types written in a .d.ts file in javascript. You reference them with the JSDoc annotations.

And no it's not the case you may as well write typescript at that point - because you're still using the actual language the browser runs, and not transpiling.

> You can't import JSDoc types from other files

Yes, you can. Using `import('./someFile').SomeType`

Though I do agree, JSDoc works, but isn't as nice as directly writing types in a .ts file