12 ms·
TypeScript at Google
- chrisco255 8y agoI wish they would make a JS/TS-based version of the Closure compiler. I suspect a lot of apps would benefit from the compilation and we'd see much smaller bundle sizes. But the Java dependency is a burden to bear.
- zdragnar 8y agoIsn't there already one? I seem to recall that it mostly works, just much more slowly than the java version Edit: here you go: https://www.npmjs.com/package/google-closure-compiler https://www.npmjs.com/package/google-closure-compiler
- chrisco255 8y agoNice! Didn't realize this was a thing. I suspect they could make even more aggressive optimizations if they made a TS version.
- evmar 8y agoThis idea is probably worth a post of its own. I believe that because TypeScript's type system is effectively advisory rather than guaranteed ('unsound'), you cannot rely on it for optimization unless you're willing to unpredictably break programs.
- bcherny 8y agoHey, that’s an interesting thought! If you go all the way and make it sound with variance annotations, banning asserts & under specified types, etc. then you end up with a language that sucks to use in practice. If you go to the other extreme, you don’t have static types at all. If different parts of your code are typed to varying degrees, or you use a lot of unsound types/inferences, maybe there’s a way to assign a confidence score to every type to indicate how accurate you think it is. Maybe there’s a clever way to statically compute that score, or you can instrument some % of prod traffic at runtime to observe types with lower confidence (Node has this, or see MonkeyType or Reticulated Python). Then take that info and feed it into Closure compiler.
- wwwigham 8y ago> If you go all the way and make it sound with variance annotations Variance annotations aren't quite what would make the language (in strict mode) sound. Specifically, what makes it unsound is the `any` type (generally) and the lack of enforced variance on methods, non-function properties, and index signatures. It doesn't need annotations to determine variance - type parameter variance can be inferred from where in a type a type parameter is used. It already does so for functions (that's the strict flag's strictFunctionTypes subflag). The real issue is that far, far too many people rely on, eg, unsound array assignments (array aughta be invariant over what it contains but it's often treated covariantly), for it to be reasonable to be a default. However it could always be changed (or added) in the future - that's what the strictness flags are for, ideally; providing ways to ratchet up the safety such that it won't permanently break longtime users of the language.
- bcherny 8y agoTotally agreed. The reason to have variance annotations is the language becomes unusable without them. Thats why so many languages with object subtyping support them.
- evmar 8y agoAs far as I understand it, every sound language eventually has to fall back to runtime checks to maintain soundness in tricky cases. For array covariance I know that Java/Dart eventually use runtime checks on array accesses to verify the types work out. However, it's kind of against the spirit of TypeScript to insert runtime checks. For example because the type system models 'undefined', to model out of bounds array accesses you'd either need to make every array access have type T|undefined or insert bounds checks that throw. (I believe Dart does the latter.)
- TheAceOfHearts 8y agoThere's a JS version of the Closure compiler [0]. And the version shipped on NPM [1] has options for either native, Java, or JS. [0] https://github.com/google/closure-compiler-js https://github.com/google/closure-compiler-js [1] https://www.npmjs.com/package/google-closure-compiler https://www.npmjs.com/package/google-closure-compiler
- suzzer99 8y agoGoogle Maps definitely made JavaScript cool at a time when it was not much in favor - people still thought Java Applets or Flash were going to rule the web.
- mattferderer 8y agoI'm hesitant to work in any JavaScript code base that isn't using TypeScript at this point. Two years ago, it was painful to use as any early release is but the benefits were obvious. My biggest wish for TypeScript is that it was easier to use experimental flavors that supported JS features currently being considered, such as the pipeline operator proposal.
- d357r0y3r 8y agoYeah, agreed. If I were looking for a regular job, I would probably filter employers based on whether they use TypeScript or not at this point (assuming it was some JavaScript-adjacent project). I'm not sure if there's really a good way of doing this sort of filtering.
- TheAceOfHearts 8y agoTypeScript was released in 2012, I wouldn't call a 4 year old tool an early release. And if you were already using Webpack picking it up was as easy as adding a loader. IMO, using such early proposals isn't worth the risk in production. Especially for proposals that are so young that they haven't even settled on a clear spec as to its behavior, like the pipeline operator.
- egeozcan 8y agoSorry this is self promotion but I think it's relevant if you need something like the pipe operator now: https://github.com/egeozcan/ppipe https://github.com/egeozcan/ppipe It's also ironic that I couldn't write this in Typescript because I simply couldn't figure out how. These days when I use my helper, I just use any and cast the result. It sucks but until I figure out how to type proxies and use variadic generic type parameters (if and when these are supported) I don't have another solution.
- leppr 8y agoThe "official" Typescript solution to variadic type parameters is to write a bunch of overloads covering the most frequent cases, e.g. from 1 to 5 parameters.
- markn951 8y agoWe’re going through a similar process at my company - how do we refactor the decade old startup-style JS without 1) spending a year rewriting everything from scratch generating little business value and potentially introducing regressions in the process 2) continuing to build stuff on that shaky house of cards. It looks like the solution we’ve kind of settled on has also been TypeScript. At this point it’s probably sub-5% of our prod code that’s TS source, and it’s daunting given how much we have to change and how many years it will take at our current pace, but it is the middle ground moderate way and probably the right way to approach things like this.
- underwater 8y agoHave you looked into Flow? This is the type of project it’s suited for (gradual typing). Facebook were in a very similar position when they created it. You can add a Flow pragma to a file and immediately get useful feedback based on Flow’s type inference.
- Zalastax 8y agoTypeScript supports doing that as well :) https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files https://github.com/Microsoft/TypeScript/wiki/Type-Checking-J...
- underwater 8y agoIn theory Flow has a stronger inference engine than TypeScript, which means it's more suited to incremental adoption. TypeScript is based on an AST; which means it's inferences are limited. For example it requires you to type the parameters to a function. If the return type is derived from untyped parameters then TypeScript falls back to typing the return type as 'any'. Flow maps the flow (hence the name) of types throughout an application, which means that it can derive the signature of a function based on the types that are passed into it. That should mean that it's a little easier to add to an existing project. Here's an example of Flow finding an error without any type annotations: https://flow.org/try/#0PTAEAEDMBsHsHcBQBjWA7AzgF1AQwCb4BMoAvKABS4CUZAfKAN6KiuiqY4BGZeoA1KCIBuFmwBOAUywBXcWlBdRAX0Qp02drwLEKARmqjkAOiywAqgAdLk8QGFcGSRUNA https://flow.org/try/#0PTAEAEDMBsHsHcBQBjWA7AzgF1AQwCb4BMoAv... And TypeScript missing the same error: http://www.typescriptlang.org/play/#src=const%20add2%20%3D%20(a)%20%3D%3E%20%7B%0D%0A%20%20%20%20%2F%2F%20TypeScript%20types%20'a'%20as%20'any'.%0D%0A%20%20%20%20const%20b%20%3D%20a%20%2B%202%3B%0D%0A%20%20%20%20return%20b%3B%0D%0A%7D%0D%0A%0D%0Aconst%20c%20%3D%20add2(1)%3B%0D%0Ac.toUpperCase()%3B%20%2F%2F%20TypeScript%20misses%20this%20error http://www.typescriptlang.org/play/#src=const%20add2%20%3D%2....
- Karupan 8y agoI love typescript as a JavaScript developer, but having used go for personal projects, I find the type system complex (maybe necessarily so). Having said that, I cannot thank TS enough for how it’s made life easier when working on and refactoring large codebases.
- smt88 8y agoI don't know what you find complex about the type system, but I actually find it slightly limiting. They keep improving it, so it can express about 95% of what I want, but I still hit situations where I can't tell the compiler everything.
- MuppetMaster42 8y agoI'm the same. Anything I do, I make sure it's in typescript because I find it easier to write than standard js. Generics are a complex concept for people to grasp without some time playing and reading docs, but once you learn it, you can express almost everything you want. But for simple projects you can get away with all but the most basic of generics, if any at all. With the release of conditional types, I find most of my js typing cases are covered. Though tbh I've always leant toward the side of "if you can't express it easily, then you're being to JavaScripty".
- bcherny 8y agoWhat sorts of things do you have trouble expressing with the type system?
- smt88 8y agoI can't think of something off the top of my head, but it's usually related to generics. I'll type something that makes sense, but the compiler doesn't like it. Another issue is that handling of string literals as types can be wonky when they're being compared against the type "string", which they should always satisfy but sometimes don't.
- 8y ago
- martzcodes 8y agoSo... I love Typescript, but... "Because TypeScript already mostly works — that's part of the reason to adopt it"... c'mon
- shadowmint 8y agoI feel like this sort of organic growth (for typescript) is a very healthy sign for a project. ES6 (or whatever we’re supposed to refer to it as now) is good enough for many things, but when you see it used heavily with, for example, proptype hints... you get the feeling that there really is a trend these days towards flavoring static type checking and the error checking that offers. I think its an interesting shift, with python and javascript both being poster child dynamic languages, but people who use them seriously going... ‘yeah, type checking is actually pretty handy...’.
- lugg 8y agoI feel like for production I would want a clean upgrade path to whatever JavaScript implements in the future. Can typescript and code converters provide this? (The article sort of touched on it.) Sadly, standards seem to be sitting on their thumbs with weak excuses - people doing it different ways therefore we do nothing. Just take the larger market share compiler, add a few handy features from others and call it a day. https://ecmascript-daily.github.io/pages/status-of-static-typing-in-ecmascript/ https://ecmascript-daily.github.io/pages/status-of-static-ty...
- whatever_dude 8y agoOne of the goals of Typescript is to be closer to what JavaScript _will be_, rather than create something new. You won't see chunks of code that need to be rewritten. That said, yes, you can compile TS to JS with no ecmascript compatibility constructs to just remove types and essentially "eject" TS into JS.
- EE84M3i 8y agoSorry if this is a well known term but what is a "proptype hint" in this context? I can't seem to find any references for '"proptype hint" "javascript"' or any variations that come to mind on Google. Edit - changed previous sentence to "proptype hint". I originally erroneously read the parent as saying "prototype hint" which I couldn't find results for, but even after correcting my reading error my question still stands.
- leetbulb 8y ago> But that's what we engineers do: we make interesting compromises that attempt to balance different concerns. I like this :)
- deleted 8y ago[deleted]
- TheAceOfHearts 8y agoGoogle has enough resources for someone to write a transpiler that can take annotated JS and convert most of it to TypeScript. It's certainly much more pleasant than having to type random comments everywhere, which kinda makes syntax highlighting way less useful. Oh, and last I checked there were no editor plugins for linting Closure Compiler annotated code. Another option would be to add TypeScript support to Closure Compiler, although it doesn't seem likely since there's no spec to guarantee compatibility. I'd love to see Facebook, Google, and Microsoft team up in this space, instead of creating 3 separate but very highly similar tools. Also, while we're talking about Closure, let's take a moment to appreciate its amazing UI toolkit [0]. I'd still consider many of their widgets to be the gold standard. It's written with desktop clients in mind and is incredibly feature-complete. I believe it also has pretty good accessibility, although I haven't personally tried that out. Oh, and don't forget the i18n as well! The closure library definitely has a lot of quirky aspects to it, but it's still quite amazing if you consider its age and how much stuff it supports. It's worth taking a few minutes to browse through their docs [1]. [0] https://google.github.io/closure-library/source/closure/goog/demos/index.html https://google.github.io/closure-library/source/closure/goog... [1] https://google.github.io/closure-library/api/ https://google.github.io/closure-library/api/
- evmar 8y agoI couldn't tell from your wording if you knew this already, but we wrote a JS->TS converter too. I didn't call it out very clearly but it's the second to last link in the post. I am really sad that TypeScript gave up on their spec. It previously was one of the strengths of the language that I was happy to cite. I guess it's a common crutch for languages (Python and so on) to say "the implementation is the spec" but without a spec to guide you, you lose sight of which features are intentional or accidents or even what the distinction between the two are. The Closure library does has some great stuff in it. It's the accumulation of years of experience of working around lots of really subtle issues in lot of browsers. On the other side it also has a lot of code for issues that are obsolete, and it's hard to know which pieces are for what.
- bearforcenine 8y agoGoogle did a bit of work on converting Closure annotated JavaScript to TypeScript. It's called Gents and it's part of the Clutz project https://github.com/angular/clutz/tree/master/src/main/java/com/google/javascript/gents https://github.com/angular/clutz/tree/master/src/main/java/c... We used it at Lucid when we converted our codebase from Closure annotated JavaScript to TypeScript. https://www.lucidchart.com/techblog/2017/11/16/converting-600k-lines-to-typescript-in-72-hours/ https://www.lucidchart.com/techblog/2017/11/16/converting-60... Google has support for using TypeScript in Closure annotated JavaScript via Clutz: https://github.com/angular/tsickle https://github.com/angular/tsickle It also has support converting TypeScript to Closure annotated JavaScript via tsickle: https://github.com/angular/clutz https://github.com/angular/clutz Before we converted all of our codebase to TypeScript we used both Clutz and tsickle. It was complicated to setup, but it worked. Now we just use tsickle. It's great to get the optimization of the Closure Compiler while using TypeScript.
- fogetti 8y ago[Irony on] It's somehow reassuring that Google engineers also "check StackOverflow for answers". Helps me to raise my low self-esteem. :D I thought all what Google engineers do is writing code from scratch in brainfuck all day long.[Irony off] Of course I am just joking. Well, the author faced the same dilemma that we all face when instead of joining the next-to-be-unicorn startup we join an established company which has been operating for more than one decade. Namely legacy code. They should pick up a copy of 'Working effectively with legacy code'. They might extrapolate some of those advices and apply to their situation.
- JAdamMoore 8y agoAll I ever do with TypeScript is spend a lot of time deleting it... just like the computer does.
- eksemplar 8y agoI always wonder why people think typescript is a fix for bad code. We primarily do JavaScript, and I see no issues with it when you set up governance in how to use it. I don’t think building your own libraries is really a bad thing either, in fact I think you should do so often instead of relying on 3rd party packages of quality you typically judge on how many times they’ve been downloaded if you’re being honest. I think typescript is silly. It works with legacy code, sure, but if you’re refactoring you might as well rewrite your JS or if you’re compiling to JS you might as well chose Dart which is vastly superior to typescript. I don’t really see type safety as an issue. I can’t remember when it was a problem for us, and we operate millions of lines of code, but they are all written with governance. Want a number? Then call your argument numWhatever and check your input. It’s really as easy as that. I mean, sure type checks will prevent shitty code from compiling, but really, just don’t write shitty code. I know that sounds silly to some people, but 95% of what you write is about shifting data around through simple mechanics, it really shouldn’t be so hard to do it right. You won’t see an engineer go “oops that support beam in your building wasn’t right, my bad” and programmers really shouldn’t get that luxury either. If they write shitty code then figure out why, maybe they need more time, maybe they need training, maybe they need governance or maybe they need to be replaced. But hey, feel free to fix your shitty code with code that’s only less shitty because your compiler protects you. Just know that typescript comes with a different set of risks, once you need your JS codebase to move forward in a way that isn’t supported by JS.
- machiaweliczny 8y agoTypescript is superior for refactoring.
- s4vi0r 8y agoAs somebody migrating a React codebase from JS to TS, I can't believe how popular TS is. It seems like something that only exists due to the popularity of Angular, where I can only assume the experience is significantly better than with React. The type system is frankly disappointing, and the errors the compiler spits out at you (besides the most obvious ones) are almost always useless or gibberish and at times even more harmful than helpful. It's better than nothing I guess, but I can't help but feel extremely underwhelmed with it given how many people use it. Are all of the people in this thread Angular developers or something?
- geewee 8y agoWhat TS version are you on? The error messages are definitely one of the weak points, but they've been massively improved for many cases in 3.0. FWIW I use Typescript with React, have had very few bad experiences(but not zero) and I'm never going back.
- s4vi0r 8y agoThe most recent, 3.0.1 I believe? Or 3.1.0 - whatever it is. As far as going back goes - it's preferable to plain JS I guess? But that's not saying all that much. I don't know - I'm sure I'll appreciate it more after this migration period is finished and things start to stabilize, but as of right now I'm definitely not enjoying it.
- elbear 8y agoI used TypeScript with Mithril and I really liked it. I'm not going back to plain JS ever again.
- rukenshia 8y agoI feel you and I think it is more of a "React + TypeScript" problem than a TypeScript problem. We have started using Angular 2 (now.. 6?) with TypeScript for a project last year and I never had big issues with TypeScript. Last month, one of our teams started a React project and given the success of using TypeScript before, they opted to do the same with their project. I've walked them through a few things but found myself getting frustrated a lot with weird TypeScript errors. Especially things like typing your Props was such a nightmare that we resorted to "any" a lot more than I'd like. The project is not using TypeScript 3 so I am unsure whether that would get rid of some problems but React + TypeScript was just a frustrating experience for us.
- theprotocol 8y agoI haven't used it in a while. Does it play nice with plain-JavaScript libraries from npm yet? I quit using it a few years back because it was a _nightmare_ having to write d.ts files for everything or be unable to use noImplictAny for your own files. `AllowJs` wasn't even a thing when I started using it, but even after its addition, this problem continued to be absolutely disastrous for my project. I remember being very disillusioned with it because all of their materials (website, docs) kept hammering on how effortless and incremental it was to use with JavaScript, yet `AllowJS` wasn't even a thing for the longest time... I also had very severe issues with its importing of npm modules, even ones that supported TypeScript. Sometimes it would double-parse bundled d.ts files resulting in a huge error output. Other times it would just completely fail to resolve import paths no matter what I tried. I remember various workarounds like having to define empty modules for each plain-JS import, or using `///` imports for certain files, and it was a nightmare (and I found many similar issues on StackOverflow that were unsolved). The maintainers at the time considered these terrible workarounds as valid solutions, and thus would almost not even entertain reports regarding these problems.
- Vinnl 8y agoIt's got to the point where, for me, TypeScript support is an important feature of a library that influences my decision whether to pick that library over another. Luckily, most of them these days either ship with their own definitions, or have them available. Bottom line: I never write my own definitions for other projects.
- bodas 8y agoI don't have any problems, just use require() for libraries that don't have TypeScript definitions. I wouldn't bother writing .d.ts files for the libraries you use, just be more careful using them.
- qudat 8y agoThere are very few libraries that I need to write type definitions for. However, they do not always get them right and sometimes can prove to be annoying when the typedefs do not keep up with latest versions of the third-party library. Any library I write now is done with typescript so typedefs are automatic which is fantastic.
- lexy0202 8y agoI'm still reluctant to use TypeScript given that it has a serious type narrowing bug that is two years old! You'd think Microsoft could have sorted this out by now. https://github.com/Microsoft/TypeScript/issues/9998 https://github.com/Microsoft/TypeScript/issues/9998
- galfarragem 8y agoIsn't Reason/Ocaml a better direction than Typescript? I believe that TS is a step forward but I'm afraid that we are still in a muddy path.
- vvpan 8y agoI hear ya, but the author of the article needed something that could be adopted _incrementally_. JS is a subset of TS. Throwing some typing onto a JS file is often trivial. Reason would be a whole different story. Learning curve alone...
- jpswade 8y agoI think the most fascinating thing here is that Google are turning to a language developed and maintained by Microsoft.
- h1d 8y agoIt's come to a time that discriminating MS was an old thing.
- jpswade 8y agoOr maybe it's about Microsoft's continued influence, especially in the Open Source community.
- STRiDEX 8y agoThey forked it for a while, called AtScript [0] and then later merged efforts. So don't think they didn't try. There's things like Tsickle [1] that converts typescript for their closure compiler [0] https://en.wikipedia.org/wiki/AtScript https://en.wikipedia.org/wiki/AtScript [1] https://github.com/angular/tsickle https://github.com/angular/tsickle
- Tade0 8y agoAfter a few years with both TS and JS my verdict is that TypeScript definitely helps, but mostly with type-related bugs - with proper testing you don't get many of those. What I would like to have in TS is a more expressive type system - the current is somewhat basic(e.g. you can't have a Symbol as a dictionary key - interesting given that it's possible in JS. Also you can't mix dictionary fields with regular ones in one class/interface). EDIT: typo.
- mcny 8y agoI don't understand language design or expressiveness but I'm ok with going slow and being restrictive. I think what we need is a subset of JavaScript, not a superset. There are things we should not be able to do in JavaScript in a web browser because to me that's where JavaScript belongs. I think the whole idea of js on the server or in other kind of projects is very silly. But that's besides the point. But I agree with your example of symbol in dict. I would be surprised if it isn't already on the roadmap. Have you tried reaching out to the typescript people?
- wwwigham 8y ago> But I agree with your example of symbol in dict. I would be surprised if it isn't already on the roadmap. Have you tried reaching out to the typescript people? It's not just on the roadmap, it's in code review/iteration as of last week: https://github.com/Microsoft/TypeScript/pull/26797 https://github.com/Microsoft/TypeScript/pull/26797
- jeremyjh 8y agoThe point of type checking isn't so much to prevent bugs in production, but to speed up your development loop by catching many errors before you've even saved your file. Its much faster to see a red squiggly right after you've written a line of code, and fix it, rather than figure out whats gone wrong 10 minutes later looking at a stack trace in your test suite.
- askmike 8y agoDoesn't this 100% on your personal develop workflow? I for one have been forced to use typescript in the past, and am personally very happy that I don't have to anymore.
- modernerd 8y agoThe author says they contemplated an “abandon this ruined planet” option, mentioning Haxe/Clojure/Elm as alternatives. I'd love to read their follow-up post to learn what kept them on planet JavaScript/TypeScript. The alternatives to TypeScript seem increasingly compelling to me. It was good to see Haxe mentioned even in passing; I really enjoy using it and — as others have noted[1] — it feels like a “better” TypeScript. Haxe has great features both at the language-level (pattern matching, algebraic data types, array comprehensions, and more[2]) and tooling-level (cross-compilation to JavaScript, native code and dynamic languages, a fast compilation server[3], good VS Code support in Haxe 4, and a bunch of cross-platform game frameworks[4]). I wish more people would try it! https://haxe.org/ https://haxe.org/ Reason is also compelling; it will be better still once Bucklescript's Belt library is out of beta and some warts in Reason/OCaml are smoothed out — lack of ad-hoc polymorphism[5] and lack of unicode support without BuckleScript string literals being two examples. [1]: https://news.ycombinator.com/item?id=10009290 https://news.ycombinator.com/item?id=10009290 [2]: https://haxe.org/documentation/introduction/language-features.html https://haxe.org/documentation/introduction/language-feature... [3]: https://haxe.org/blog/nicolas-about-haxe-episode-1/ https://haxe.org/blog/nicolas-about-haxe-episode-1/ [4]: https://haxe.org/use-cases/games/ https://haxe.org/use-cases/games/ [5]: http://ocamllabs.io/doc/implicits.html http://ocamllabs.io/doc/implicits.html
- evmar 8y agoThe mastermind behind our TypeScript project commented on this topic here: https://news.ycombinator.com/item?id=17896925 https://news.ycombinator.com/item?id=17896925 I used to tinker a lot with OCaml around 13 years(!) ago. It's neat to see people are still working on fixing some of its problems. It would be fun to find a reason to use it again.
- bazza451 8y agoReal big fan of TS, like anything though you just have to be disciplined when using it. Type absolutely everything and set the transpiler to the most aggressive checks possible... If you’re being lazy and putting : any everywhere and then complaining about how good it is...you’re doing it wrong In our project I’ve found we make a lot less mistakes than with pure JS and there’s a lot less pointless type check unit tests due to the guarantee’s it gives us. io-ts (https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts) around rest endpoints checking json input as well has been a godsend.
- adwhit 8y agoI always use it with > "compilerOptions": { "strict": true } But given the huge number of other options I worry that like GCC's '-Wall', that doesn't actually give you the strongest possible type checking. Anyone know about that? My aim with Typescript is to turn JS into OCaml.
- stefano 8y ago> My aim with Typescript is to turn JS into OCaml If that's the goal, why not use the real thing http://ocsigen.org/js_of_ocaml/ http://ocsigen.org/js_of_ocaml/ ?
- scottmf 8y agoSo... ReasonML?
- PinkMilkshake 8y agoYou might like https://bucklescript.github.io/ https://bucklescript.github.io/ Facebook use it in Messenger.
- michaelmcmillan 8y agoI share your view! Unfortunately, getting devs to write proper unit tests is – for whatever reason – difficult. Types just smuggle themselves in with the rest of the program (granted they only cover a subset of the bugs tests do).
- nathan_f77 8y agoI wonder if it's worth migrating from Flow to TypeScript? Flow has been great, but I've just tried to update to the latest version and I'm dealing with a flood of indecipherable errors, especially from the react-dnd library. Looks like no-one is really maintaining the flow types so I'm on my own, and I don't even know where to start. I also haven't been able to track down some errors, like "Cannot read property 'foo' of undefined". Flow thinks that this variable can never be undefined, and I have no idea how it's happening. It might even be a bug in Immutable.js, but I have no idea. So if TypeScript is more popular and has a bigger community, then maybe it's worth migrating just so I can get more help with these issues. And maybe TypeScript will catch more cases as well.
- stephen 8y agoYes.
- AriaMinaei 8y agoThat's what I did. I switched to TypeScript after two years of being both heavily invested in Flow and advocating it. The reason I initially chose Flow was the fact that their goals were more ambitious (trying to build a sound type system for example). And there were features that Flow had and TypeScript didn't (tagged unions for example). The reason I ultimately switched to TypeScript was that after a couple of years, it had simply caught up and surpassed in the one area it was behind Flow (i.e. expressiveness of the type system and type-level programming), and that it had widened the lead in the areas that it was always better at, like much better tooling, bigger community, core team being more engaged with the community, releasing RCs to smooth out the rough edges, etc. So yes, I switched to TypeScript, and I see that I'm spending less time working around the type system's quirks and more time getting things done. I'm also very much enjoying the fact that I can express types in TS that I never could in Flow. So my codebase has much better type coverage in TypeScript than it did with Flow. [0] https://www.typescriptlang.org/docs/handbook/advanced-types.html https://www.typescriptlang.org/docs/handbook/advanced-types....
- davnicwil 8y ago> much better tooling If you have the time, would you mind commenting specifically on this? I'm using Flow, rather than TS, for a bunch of reasons you are probably familiar with, but over time I'm just wondering more and more if switching to TS might be worth it just for the tooling. With Flow in VS Code (via the flow-for-vscode plugin), whilst things have slowly and steadily improved over the last 2 years it is still quite a way from 'just works'. I get the impression that the story for TS with VS Code is a lot different, and everything would just work out the box (intellisense, auto import, meaningful error messages tied to line numbers, etc) though I simply haven't yet found the justification to invest the time in migrating just to check this. If I'm wrong and it's the same or only very slightly better, it would obviously have been a time sink for not really much benefit. Do you have any insights or advice on this? Even if you're not a VS Code user, what tools do you use that are better with TS than Flow?
- cribbles 8y ago> Gmail engineers had to worry so much about Internet Explorer's poor garbage collection algorithm that they'd need to manually hoist string literals out of for loops to avoid GC pauses. What does this mean in practice? I know about variable hoisting and function scoping, but not about old JS GC algos.
- MBCook 8y agoMy read was that Internet Explorer couldn’t realize that a string variable could be reused over and over so each iteration of the loop it was allocating a new one, using it, and then garbage collecting it. Basically tons of unnecessary overhead. Having the programmer define a variable before the loop and then reuse it each iteration meant that all that allocation and garbage collection wasn’t necessary during the passes of the loop.
- evmar 8y agoThat is exactly right.
- sheeshkebab 8y agoWhat js in browser is missing is something that golang provided on the server - fast, simple (and more standard) way of writing and executing code, including large code bases. Typesafety is a small part of it and I’m not sure whether switching or choosing entire dev tooling based on just that is worth it. Just structure your code better and use react prop types and most of type issues go away, in react code bases.
- KeitIG 8y agoProp-types is for runtime, TS does static type checking. Prop-types are terribly verbose and only work with React (what about utils files, external libraries, etc?).
- Nitramp 8y ago> The first tempting option is to just abandon this ruined planet and settle a new one that doesn't even involve JavaScript. If only we invested more in GWT (a Google project that compiles Java to JavaScript) or Dart (a Google project that compiles a new language to JavaScript) or WASM or [insert your favorite language here — Clojure? Haxe? Elm?] we wouldn't need to worry about JavaScript at all! I thought about this for quite a while when we started on TypeScript at Google (I work on this with Evan). I've convinced myself that using a different language cannot solve the problem that we're looking at. The argument goes like this: if you use a different language than JavaScript for front end development, you're (hopefully) doing it for a reason. That is, you (a) want the other languages semantics (e.g. bounds checks on array accesses, runtime types, method dispatch, you name it), or you (b) might want the programming languages ecosystem - editors, IDEs, etc; but most importantly libraries and frameworks. Most likely, you're looking for a combination of (a) and (b). The problem with (a) is that the more different the runtime semantics of your programming language are, the more emulation code you need. Emulation code is costly in code size, performance, interop with JS, and often understandability (at some point you will need to debug the output, believe me). The problem with (b) is that you typically opt into a large ecosystem that was originally written for a very different environment. This was a big issue with GWT: people would pull Java libraries, but those libraries, amazing as many are, were not written for the web or with code size in mind. This meant using a common library like Guava required a lot of engineering effort to keep code size in check. This also applies to WASM, possibly even more so. These mechanisms work together to make it very hard to hit the sweet spot between performance, developer experience, and interoperability. And ironically, the better you get at the goals you're aiming for (different semantics, different ecosystem), the farther you get away from a working solution. I don't think it's impossible to achieve a transpile-to-JS language that works really well with enough investment, but keeping in mind the other reasons Evan lists (mind share, existing code base), incrementally improving JavaScript where needed is IMHO the much more promising approach.
- Bjartr 8y agoTechnically GWT is still an active project. They're (slowly) working towards a 3.0 release. I use GWT in my day job.
- willy8 8y ago> it's likely if you use Google products you've interacted with some TypeScript code Transpiled Typescript code I expect, so?
- munificent 8y ago> If only we invested more in GWT (a Google project that compiles Java to JavaScript) or Dart (a Google project that compiles a new language to JavaScript) or WASM or [insert your favorite language here — Clojure? Haxe? Elm?] we wouldn't need to worry about JavaScript at all! I'm on the Dart team. I don't know if the author intended this, but you could read this as saying that Google isn't investing much in Dart, which isn't true. Flutter and Fuchsia are the high profile projects that use Dart. AdWords is also built in Dart. The Dart team itself is as large as its ever been and growing. (I'd give more precise numbers, but Google generally shies away from publicly stating personnel details.) We have a ton of internal and external code written in Dart, and it's growing at a nice clip. Different projects have different needs. If you have a large existing JS corpus that's providing a lot of value for you, then an incremental migration to TypeScript makes sense. If you're looking to rewrite a lot of code and pay off technical debt anyway, then moving to a new language that doesn't have all of JavaScript's baggage can be a smarter choice. Dart has a cleaner object model and fewer warts like "===", etc. Making a bigger break from JS means that Dart's type system can be simpler than TypeScript's and is sound. That in turn means the compiler can rely on types for optimization and minification.
- jadbox 8y agoI mostly know Typescript, but I'd like to learn more about Dart... particularly where the type system differs in theory. Do you have a good recommended article on that? The other question is the community one: if Dart requires type bindings (like TS .d.ts files) to the large community of JS projects, how does it plan to solve the kickstart problem. It's taken TS community many years to over just the popular js libraries out there. Imho, I'd make a utility to convert/translate TS definitions into Dart wrappers... but that would require to support TS primitives almost 1:1. None of this is meant to sound critical, I'm just genuinely curious on the process of language development.
- munificent 8y ago> Do you have a good recommended article on that? I don't, but I agree it would be useful. We're not where I wish we were in terms of docs right now. > if Dart requires type bindings (like TS .d.ts files) to the large community of JS projects, how does it plan to solve the kickstart problem. We actually have a tool that will generate the proper Dart interop bindings given a TypeScript .d.ts file: https://github.com/dart-lang/js_facade_gen https://github.com/dart-lang/js_facade_gen > It's taken TS community many years to over just the popular js libraries out there. Dart is different from TypeScript in that we are deliberately a more batteries-included system. We wrote and maintain a full set of core libraries (collections, async, etc.) and Google has a well-funded team to ship and maintain a full-featured web framework (AngularDart). So we aren't as stuck needing to rely on the JS ecosystem as TypeScript is. There is still tons of useful functionality that's available in JS and not yet Dart, which is why interop is important, but we have a lot of customers that can get by without needing much or any JS interop.
- aggre 8y agoI switched from Flow to TypeScript. Flow has some type-declared libraries, but it's fewer than TypeScript type-declared libraries. The excellence of VSCode also helps me.
- neop1x 8y agoWeb shouldn't end up this way. Web was designed for sharing documents. Webs and webapps now are sluggish and take soooo much RAM. I have a pretty fast computer with 16GB RAM but running all these webapps with Megabytes of javascript is bringing back -5years experience and can fill up my RAM. I know it is still improving but webapp developers are also quick with abusing every performance gain often for unwanted and unneded functionality. For example CSS animations for every mouse over, material clicking highlights are terrible, terrible design decisions which occassionally even spin up my laptop fan.