Live data from Hacker News

TypeScript at Google

neugierig.org

141–150 of 201 posts

Re: TypeScript at Google

#141
post #128

> 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.

My 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 pas…

That is exactly right.

Re: TypeScript at Google

#142
post #72
post #24

Earlier quoted context omitted.

Have you spent any real time with Flow? As I’m starting to get into the modern front end world… I do want the safety of a stronger type system but it doesn’t look like the React ecosystem has really decided which way to go. TypeScript is popular. But flow was developed by Facebook and so it’s obviously heavily used by some of the top people. I’ve only been reading about them, I haven’t chosen to use one yet. But I’ve…

Although it's clear that Facebook's libraries, among which React, favour Flow, there's strong community demand for TypeScript even around React. Thus, the type definitions that are available for React are excellent, Redux even includes its type definitions natively, and most of the large tools in the React ecosystem work pretty well with TypeScript. The main large project you're likely to use that does not really pla…

We're actually looking at removing the type definitions from the Redux core and punting them over to DefinitelyTyped, because neither of us primary maintainers use TS ourselves and we don't have the experience to maintain the type definitions.

Also, the CRA-TS fork runs, but the one time I played with it was when I tried to help another team set up their project, and that's when I found out it has _ridiculously_ restrictive default linting rules. Every lint error is a compile error, and it flags things like using arrow functions in render methods, which is absurd (see discussion at https://github.com/wmonk/create-react-app-typescript/issues/... ).

Re: TypeScript at Google

#143
post #48

Earlier quoted context omitted.

Hey, 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…

> 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…

Totally agreed. The reason to have variance annotations is the language becomes unusable without them. Thats why so many languages with object subtyping support them.

Re: TypeScript at Google

#144
post #112
post #41

Earlier quoted context omitted.

What sorts of things do you have trouble expressing with the type system?

I 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.

I’d love to see examples for those, maybe drop a comment when you run across a specific issue.

Re: TypeScript at Google

#145
post #48

Earlier quoted context omitted.

Hey, 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…

> 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…

As 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.)

Re: TypeScript at Google

#146

> 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…

Could these very same arguments not be applied to Javascript itself? JS is "transpiled" to bytecode, a language with vastly different semantics and a totally different ecosystem. It end up being wildly inefficient, but consumers don't seem to mind. The description of Dart is also wrong. My understanding is that they are aiming at REPLACING JS in the browser, not compile to it. Compilation to JS is a stopgap to make t…

That was their initial goal, but it's been years since they backed off of Dartium at this point.

Re: TypeScript at Google

#147
post #51

Earlier quoted context omitted.

Typescript will happily check your JavaScript code with “allowJs” compiler flag. We write all our new code in good ol ES6 flavor of JavaScript and typehint in jsdoc. Typescript as a typechecker serves as very well. It’s a great incremental adoption strategy.

can you explain how this works ? this is very interesting to us. We have a large react app (created using create-react-app) in ES6 and have been considering adopting TS gradually. This seems a great first step.

AFAIU, just add typescript to your project or globally then in your project set a tsconfig.json file with the allowJs and esModuleInterop flags set to true. Don’t quote me on this but you can probably leave out most of the rest of the flags besides your source location. For example:

    {
        “compilerOptions”: {
            “allowJs”: true,
            “esModuleInterop”: true
        },
        “include”: [ “src/**/*” ],
        “exclude”: [ “node_modules/**/*” ]
    }
You’ll probably have to tweak that, but I hope it helps.

https://www.typescriptlang.org/docs/handbook/compiler-option...

Re: TypeScript at Google

#148
post #51

Earlier quoted context omitted.

Typescript will happily check your JavaScript code with “allowJs” compiler flag. We write all our new code in good ol ES6 flavor of JavaScript and typehint in jsdoc. Typescript as a typechecker serves as very well. It’s a great incremental adoption strategy.

can you explain how this works ? this is very interesting to us. We have a large react app (created using create-react-app) in ES6 and have been considering adopting TS gradually. This seems a great first step.

See https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-i...

Also Google’s puppeteer project is typechecked with tsc and the type info is all in jsdocs

https://github.com/GoogleChrome/puppeteer

Re: TypeScript at Google

#149
post #49

Earlier quoted context omitted.

Typescript compiler architecture is quite different to flows. Typescript was written from the get go to provide really fast and accurate intellisense to IDEs. The newer refactoring powers are super nice too. Most ides just ask typescripts language service “hey, my user’s cursor is here, what should I show for code completion?” I think that’s what differentiates TS from flow. Typescript thought about the whole develop…

To Flow's credit, their language server does provide IDE features: https://github.com/flowtype/flow-language-server#supported-f... I still have found TypeScript to be an overall more pleasant developer experience, though.

That’s awesome, I didn’t know that.

Re: TypeScript at Google

#150

I 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'…

That'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 year…

> 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?

Post reply on HN