Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Meeting Notes, 5/6/2016 #8503

Closed
RyanCavanaugh opened this issue May 6, 2016 · 3 comments
Closed

Design Meeting Notes, 5/6/2016 #8503

RyanCavanaugh opened this issue May 6, 2016 · 3 comments
Labels
Design Notes Notes from our design meetings

Comments

@RyanCavanaugh
Copy link
Member

  • Check non-undefined properties are initialized in the constructor with --strictNullChecks #8476 - Uninitialized non-null properties in classes
    • Definitely going to break some code patterns
      • e.g. a separate init method
      • e.g. initialization is done in a factory method
      • e.g. initialization is done in a second call by the caller
    • We might end up with another commandline switch, which is not great
      • You may want this flag on some classes, but not others...
    • This gets weird in abstract classes
      • Have to check the whole lineage to see what happens
    • But it's a big hole
    • We could check that you assign to it somewhere... but that's weird
    • Workaround is to initialize with <any>undefined but that's impactful and weird
    • Some syntax for declaring that an initialization happens 'somewhere'
      • x!: number;
      • x: number!; (what would x: number!|string; mean?)
      • x: number = *;
      • Ambient decorator a.k.a. attribute (which we don't have yet...)
    • Workaround: Declare it in a co-interface instead
      • Doesn't allow for private/protected properties
      • Undiscoverable
    • Potential for a ! modifier on a declaration that says "Let me treat this as non-null when convenient"
    • We should allow optional property declarations in classes
      • and methods too (they must lack a body)
    • Currently a bug that we don't properly define the type of interface X { foo?(): void; }
    • Force classes to initialize and see how bad the breakage actually is
    • What about Abstract classes and properties
      • Note that we don't really know what an ambient abstract class constructor did
      • You must initialize all properties you declare
      • Assume that concrete properties are initialized by the base class
  • 8370 - this types for accessors

    • 👍
  • 7271, Interfaces and classes considered equal #8168, Suggestion: the 'instanceof' type modifier for class and function types #8316 - instanceof

    • Anders hates classes 😉
    • What do we do with the only nominal thing in JavaScript?
    • Lots of actual code that only differentiates via prototype
    • We could do a local fix of instanceof (small + easy), or add nominal types back in some form (huge, been discussed before at length)
    • We should rewrite lib.d.ts to use classes now (we believe this to be safe)
    • 👍 treat class-declared types differently in instanceof
    • What about user type guards?
      • You could write x instanceof T instead of x is T in the predicate form
      • Or just say that is T is like instanceof T when T is a class type
    • (Extensive argument about nominal vs structural classes)
@jkillian
Copy link

jkillian commented May 6, 2016

👍 Thanks for writing these up - I'm sure they're an organizational help for the TS team, but they also are great for external TS users (like me) interested in where TS is going and the learning about the challenges in creating a language like TS.

@tinganho
Copy link
Contributor

tinganho commented May 7, 2016

Some syntax for declaring that an initialization happens 'somewhere'
x!: number;
x: number!; (what would x: number!|string; mean?)
x: number = *;
Ambient decorator a.k.a. attribute (which we don't have yet...)

Maybe just declare a method as an initializer?

class A {
   a: number;
   init onMount() {
     a = 1;
   }
}

@basarat
Copy link
Contributor

basarat commented May 9, 2016

Extensive argument about nominal vs structural classes

FWIW flowlang has nominal classes. Everything else is structural 🌹

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Notes Notes from our design meetings
Projects
None yet
Development

No branches or pull requests

4 participants