-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design NotesNotes from our design meetingsNotes from our design meetings
Description
Stricter Tuple Types
- Tried freshness, generally encountered strange behavior.
- Adding an explicit
length
property breaks fairly little- Things we catch:
- Accidental Haskell-style list syntax:
[T]
instead ofT[]
.- This is actually a singleton tuple of
T
instead ofArray<T>
- Caught ~10 instances of that.
- This is actually a singleton tuple of
- Accidental Haskell-style list syntax:
- Actual errors where people misunderstood the API
- Found this in Highcharts & Leaflet
- Downside is you can't cast between these anymore without an intermediate.
- One break in firebase-js-sdk
- Things we catch:
- Then we tried changing tuples to extend
ReadonlyArray
instead.- Which makes tuple elements immutable which is more debatable.
- And problematically means you can't assign to array
- Didn't find many errors outside of the test suite.
- Added another break in firebase-js-sdk
- What about
push: never; pop: never;
?- Means you can still assign to arrays, but can't mutate them directly.
- Kind of cheating, but a reasonable compromise in intent.
- Well maybe, but Calling and indexing on type 'never' is allowed #11412
- Should look into this!
- Conclusion: try out the stubs, keep testing on real world code.
instanceof
checks
- Idea:
instanceof
has worked structurally since forever with us.- But because of structural compatibility, things that were structurally identical would act very strangely.
- We want to change this to actually check the base types as it does at runtime.
- Things the PR does
-
Makes
instanceof
nominal -
Changes to subtype reduction to accomodate this new behavior.
-
Take the following:
class A {} class B extends A {} class Q extends A { qProp: any; } let blah = Math.random() ? new B() : new Q();
-
Under old subtype reduction behavior,
blah
has typeB
; means the negative check forblah instanceof B
gives younever
:if (blah instanceof B) { blah; /* has type `B` */ } else { blah; /* has type `never` */ }
-
Under new behavior, we aren't as agressive;
blah
has typeB | D
if (blah instanceof B) { blah; /* has type `B` */ } else { blah; /* has type `D` */ }
-
This is better, but it affects things like callability.
-
- Do we care about how ES2015 allows this behavior to be overridden with
Symbol.instanceOf
?- Most people just don't do this.
- It's in nightly now.
KiaraGrouwstra, aluanhaddad and HerringtonDarkholme
Metadata
Metadata
Assignees
Labels
Design NotesNotes from our design meetingsNotes from our design meetings