6 ms·
Ts-migrate: tool to automatically migrate JavaScript projects to TS
- Vanit 6y agoI feel like this should be linking to the associated blog post that actually explains what we're looking at. https://medium.com/airbnb-engineering/ts-migrate-a-tool-for-migrating-to-typescript-at-scale-cd23bfeb5cc https://medium.com/airbnb-engineering/ts-migrate-a-tool-for-...
- coding123 6y agoI thought the tool to automatically migrate JS to TS was tsc --init and then set the flag to include js files.
- seattle_spring 6y agoThis tool actually converts JS files to valid TS files with strict typing, attempting to add types to everything it can and adding placeholder types where it can't.
- asutekku 6y agoThat’s just running js files within ts files. Nothing to really do with migrating, unless you’re writing everything by hand and want everything to work while you’re at it.
- agustif 6y agoWell, actually is a good base to migratee a js codebase to ts manually, one file at a time. You can leave parts in JS while you upgrade/add new features in TS
- hartror 6y agoWe just finished our TS migration, I wonder if this would have helped.
- Lammy 6y agoTo save any fellow non-webdevs ten seconds, TS == TypeScript
- thrownaway954 6y agoyou are doing God's work. Why would the submitter spell out JavaScript but abbreviate TypeScript?
- nojvek 6y agoIf I understand correctly, they convert the js file to .ts file, ask tsc for error diagnostics and automatically apply transformations to resolve those errors when they can. Yep that’s how I’d do it too. I wrote a simpler version when doing a tsc upgrade to resolve a whole bunch of errors. It parses the tsc errors and does simple string replaces. Has anyone played with the tool to report how good it is? I remember v8 did an experiment back in the day where it would run code and profile the input parameters and output of functions and automatically generate typescript types.
- triyambakam 6y agoI hadn't heard of that, but there is the typewiz project - https://github.com/urish/typewiz https://github.com/urish/typewiz
- swyx 6y agoI keep a list of migration tools here fwiw https://github.com/typescript-cheatsheets/react/blob/master/docs/migration/from-js.md#automated-js-to-ts-conversion https://github.com/typescript-cheatsheets/react/blob/master/...
- goofballlogic 6y agoIt would be nice if we somehow had one to convert typescript back into _idiomatic_ JavaScript.
- aaomidi 6y agoRun the typescript compiler with ESNEXT
- hardwaregeek 6y agoI've wondered if you could run JS code, keep track of runtime types, and generate interfaces off of that. Of course the program wouldn't know what to name the interface, but it's still better than nothing.
- agumonkey 6y agoThis is interesting, it would be great to make this a general tool. Extract invariants from untyped runs to generate tests/interfaces or else. Migrations would be smoother.
- jrib 6y agoGenerating starting points for interface definitions based on runtime logs does sound like a good idea. There's a similar project I'm aware of that uses runtime behavior to help create type annotations but for python: https://github.com/instagram/MonkeyType https://github.com/instagram/MonkeyType
- cryptica 6y agoThis tool is ridiculous and less than useless. Can't anyone else see how ridiculous of an idea it is to add types automatically? Isn't the whole point of static typing to allow the human developer to specify what the types should be? If a machine could resolve the type integrity issue automatically from dynamically typed code (which is what this tool claims to do), why do we need this tool to physically insert type annotations into the code to begin with? I can't believe I even have to explain myself. I thought static typing was meant to protect the code's integrity? Clearly this tool is undeniable proof that static typing exists merely to satisfy human ego and neuroticism and has nothing to do with logical integrity... Since this tool itself supposedly proves that this integrity can be derived automatically from dynamically typed code. This tool is a paradox, a blatant logical contradiction. If this tool does work as advertised, then it proves the uselessness of static typing and thus, by extension, this tools proves its own uselessness. EDIT I removed a potentially offensive remark from my comment. This makes zero sense to me is my point.
- ludamad 6y agoThere's no conspiracy here, just TypeScript is now strict enough to need annotation, and the authors deemed it better to work with a valid TS file and annotate from there than loosen that strictness.
- KenanSulayman 6y agoWho hurt you? This project is meant to make developers more efficient and support them in migrating projects to TypeScript. The entire point of TypeScript is to make developers more efficient, too, through clear structuring, types and assistance through its toolchain. Static typing does not protect you from integrity issues. However, it allows you to extend existing code with confidence. I'm not sure if you work in a team, but your general attitude isn't exactly conducive to a constructive, open and efficient working environment.
- cryptica 6y ago>> Who hurt you? TypeScript hurt me. >> However, it allows you to extend existing code with confidence This argument is often used and cannot be disproved but the words "with confidence" betray the case for its objectivity. Confidence is a subjective emotion; I can tell you that I feel confident about extending my JavaScript code without TypeScript and you can't argue with that. So this is a subjective argument and my extensive subjective experience of both languages disagrees with the premise. The most innocent explanation that I can come up with is that TypeScript caters to developers who are not good at coding and thus lack confidence in their coding ability. For me, TypeScript has 0 effect on my confidence and the transpilation step makes things more complicated and makes me less productive overall. Testing is the only thing which increases my confidence in the code; nothing else has any effect on my confidence levels... Not even the language (and I used many over the years). This leads me to think that the confidence which TS gives developers is an illusion, I remember a time when I was younger and used to harbor such illusions about static typing so I'm just drawing projections about other people from my own experience. And yes, your first observation about me is absolutely correct, my skills as a developer have been thoroughly battle-tested and this has hurt me. To me, the existence of this tool is like reliving a past trauma. >> I'm not sure if you work in a team, but your general attitude isn't exactly conducive to a constructive, open and efficient working environment. My team is very productive (I'm CTO). We're productive because we're pragmatic. We don't use TypeScript because we're pragmatic. I don't have to resort to this attitude because my team members were carefully selected for having high level critical thinking and so they wouldn't make such big mistakes as creating this tool.