Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Typescript can actually use the types you provide in JSDoc[1] so you will see benefits simply by using VS Code in most cases.

[1]: https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-i...



That is interesting, I did not know that.

Still, I don't want to use TypeScript for the reasons I wrote. I'm as minimalist as possible, and I don't want to use a language that changes my code to something else without any gain for me since I can write exactly what I want in ES 2015+ already. So it's just those types, and I could get them from "Flow" too and in that case keep my ES 2015+ code. Yes I know TypeScript is very close to ES 2015+, but I never know when it does change the code unless I look at the transpiled result.

EDIT: Actually, I did know that, looking at that page I remember why I dismissed it:

  > Note any tags not listed explicitly below (such as @typedef, or @constructor) are not yet supported.
But that is something I make heavy use of. It would be really messy if I wasn't able to introduce "custom types" even in my limited "IDE based static type system".


> I don't want to use a language that changes my code to something else

TypeScript doesn't change your code. If you're writing ES2015 code and targeting ES2015 emit, the output code is always exactly what you put in. There isn't any difference.


I guess I'll have to look into that again then.


Right, most of the code changes Typescript performs are the equivalent of babel plugins: the closer you write to the target output version of the language the fewer changes there between the input/output. The further back compatible you try to target the more "polyfills" and reconfiguring Typescript needs to do to support the older versions of JS.

Most of Typescript's output changes when you are writing for the same version of JS that you are outputting are simply just removing the type hints from the final output.

That said, with allowJS "mixed" mode of Typescript now you can also try for a hybrid approach of JS and TS files in the same project and that hybrid approach gets more powerful and capable with each release. I think with some effort you can even get somewhat close enough to the point that you can have some Flow-like behavior by using JS for most files and .d.ts and .ts files for only the really type-dependent stuff.


I hope that is going to be a major use case for TS (i.e. directly intended and supported by the makers), i.e. (guaranteed) "just types".


Also you could just add types to your JavaScript code with TypeScript and nothing else; the result of running through the TS compiler is just the same code with the types removed.


Typescript is a superset of JavaScript. If you don't use any typescript features then you don't need a compile step.


For what it's worth, that is slightly out of date - I have a code base that uses `@typedef` and TypeScript seems to pick it up without trouble.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: