5 ms·
Avoid vendor locking. Someday in near future if you don't like flow anymore, you can just strip all type annotations with Babel and move on. You are not risking
by MehdiHK 10y ago
Avoid vendor locking. Someday in near future if you don't like flow anymore, you can just strip all type annotations with Babel and move on. You are not risking ending up like coffeescript.
- treehau5 10y agoAlso, you can progressively opt in to add typing information, while still getting most of the benefits without.
- whatever_dude 10y agoThe same can be done with TypeScript. Type inference has been added to it in 2015.
- treehau5 10y agoAwesome, did not know this.
- shados 10y agoTypeScript type inference is minimal though and doesn't go very far. It falls back to "any" very quickly (and if you use the noImplicitAny option, then you have to type almost everything). It does a decent enough job at return types, but not a whole lot beyond that.
- whatever_dude 10y agoDo you have a use case where something would be correctly inferred in Flow but not in TS?
- dsp1234 10y agoThe classic example is: function double(x) { return x * 2; } const result = double("foo"); Which passes in TS, but fails in Flow. In TS, the 'x' parameter to the double function is inferred as Any.
- dangoor 10y agoTypeScript compiles to JS in a straightforward manner as well. If you wanted to move away from TS, you could simply have the TS compiler compile to ES6 and you're done.
- MehdiHK 10y agoBut that'd still be transpiled code, right? After getting rid of flow it will be exactly same minus the type annotations. Same cannot be said about typescript considering various language features and syntactic sugar TS offers. Will it run? Yes. Will it feel that it was written by me? That depends.
- eknkc 10y agoWith target esnext, it produces almost the same output with some spacing differences. Sans the annotations obviously.
- Rapzid 10y agoYour equivalence with transpiling coffeescript is false. TS doesn't really have "syntactic sugars". Just about everything in it(less the types of course) is pretty far along in the ES adoption process. There are a couple exceptions like decorators that are called out in a very visible manner. If you target ES6 your code may look identical. Even much of the ES5 down leveling produced code that looks like a person wrote it. I converted a 10k line coffeescript project(with async/await !) to JS and then TypeScript. The similarities are so far apart they might as well be in different dimensions. But, if you don't want to take a rando posters word for it, it's pretty easy to make a little sample project and see if the output is to your liking.
- whatever_dude 10y ago> Same cannot be said about typescript considering various language features and syntactic sugar TS offers I think you're vastly misinterpreting what TS is. It's not anything like CoffeeScript. It's JS plus types and a few other features like Interfaces or advanced ECMAScript features when targetting older versions of the standard. If you strip away types by exporting to your ECMAScript target of choice, you'll get real JavaScript with the same style as it was written in TypeScript. It's exactly the same thing you'd get with Flow in that sense. The only additional code you'd get would be for polyfills, but a) those are minimal and b) those will only appear if you export to an older ECMAScript version than the one you wrote it in. There is no vendor lock.
- whatever_dude 10y agoThat's an objectively incorrect assertion if you're applying that to TypeScript. The same can be done to it that would be done to Flow: you can just either strip types manually, or just do a single export to your ECMAScripttarget of choice. It'll be native JavaScript. Even the little shims/polyfills it does (to support older ECMAScript versions if you wish to export to it) are optional and can be disabled.
- mohamedhegazy 10y agoTypeScript has `--target ESNext` this will strip out any TypeScript-specific type annotations, and leave you with standard-track-only JS code that looks identical to your input (modulo type annotations).
- icholy 10y ago> Avoid vendor locking. It's open source. > you can just strip all type annotations with Babel and move on. Are you implying that this isn't possible with TypeScript?
- dsp1234 10y agoIf you're afraid of vendor lock-in, but fine with comments then you can just put all of your typing information in jsdoc comments. https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-i...
- hzoo 10y agoFYI we do have an issue open about TS https://github.com/babel/babylon/issues/320 https://github.com/babel/babylon/issues/320 so that we could eventually support TS in Babel as a plugin and then create the same strip-types-plugin just like Flow.