Typescript: Design Meeting Notes, 6/14/2019

Created on 28 Jun 2019  路  1Comment  路  Source: microsoft/TypeScript

TypeScript Website Changes

  • Starting to get a more investment into the playground!
  • Clickable anchor links

    • Andrew commented that we should probably increase opacity for contrast.

  • Removing the "fork me" ribbon
  • Automatically serialize the playground to the URL bar on idle, lz compress the contents

Room for Improved Inference

  • Feels like there is room for improvements in inference
    *
    ts let map = new Map([["", true], ["", 0]]);

    • In playground, gives you number is not assignable to boolean

      *

      ts type Foo = { success: boolean }; declare function bar<T>(f: () => T[]): T[]; let x: Foo[] = bar(() => Math.random() ? [{ success: true }] : [{ success: false }]);

    • Type '{ success: true; }[] | { success: false; }[]' is not assignable to type '{ success: true; }[]'.

  • Problem a lot of the time comes down to "should we infer a union to T, or error that there's no common supertype"

    • Historically we didn't pick union types because we weren't sure about variance of usage.

    • Maybe we can do better based on variance as of strictFunctionTypes.

  • What about function push<T>(arr: T[], elem: T)?

    • Nothing telling you you're wrong.

    • Bad.

    • Maybe we need some sort of variance annotation.

    • Not clear that that's the issue.

Strict Property Initialization

class Test {
    x: number = this.x;
}
  • We decided to disallow x being referenced in its own initializer, but it maybe doesn't make as much sense in the presence of subtyping.
  • Maybe adding a ! should allow you to disable the circularity error.
  • Will this even work with changes to class property initialization?

    • Don't think so.

    • Existing engines don't seem to be compliant.

  • Resolution: figure out what should happen per spec, update the Ember people, either version of postfix bang should work.
Design Notes

Most helpful comment

Indeed, variance annotation would be very useful, specifically were it cannot be inferred (typically for declarations typings).

>All comments

Indeed, variance annotation would be very useful, specifically were it cannot be inferred (typically for declarations typings).

Was this page helpful?
0 / 5 - 0 ratings