You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Long time there's been a desire from us to narrow computed-but-effectively constant values.
Once you've proven something about obj[key] and you change neither obj nor key, the type system really should understand that!
Previously couldn't do this because typically the whole issue was that key was often a parameter, or varied within a loop variable.
But now we already have control flow analysis of parameters and let variables that don't actually mutate (and captured variables that don't mutate after a certain point).
Not everything "lights up" the way you'd think.
functionf(obj: object,key: string){if(keyinobj){obj[key];// not allowed right now}}
Can't make this work right because we don't consider obj to be indexable.
In a sense you want obj to have the type object & Record<unique typeof key, unknown>. Really wouldn't want obj to be indexable with allstrings, just key itself.
Manufacture a type variable/existential for key.
No baseline changes or issues in the top 200.
We saw a slight bit of slowdown in compiler-unions.
Preserving attributes on reference directives
#57681
preserve="true"?.d.tsbundlers?.d.tsand get the same behavior.Reallowing
Infinity,-Infinity,NaNas enum member namesBackground
#56161
#57845
enum E { "10" = 42 }enum E { "10" = 42, yadda = 10 }which breaks the reverse mapping.E[10]maps toyaddanot42InfinityorNaNenum E { Infinity = 1, yadda = 1/0 }.Infinity, what's the problem?Proposal
Discussion
enum E { yadda = 'yadda' }had a reverse mapping, it would overwrite the reverse mapping. AndRed = 'Red'is super common.Narrowing element accesses with non-constant expressions
#57847
Long time there's been a desire from us to narrow computed-but-effectively constant values.
Once you've proven something about
obj[key]and you change neitherobjnorkey, the type system really should understand that!Previously couldn't do this because typically the whole issue was that
keywas often a parameter, or varied within a loop variable.letvariables that don't actually mutate (and captured variables that don't mutate after a certain point).Not everything "lights up" the way you'd think.
objto be indexable.objto have the typeobject & Record<unique typeof key, unknown>. Really wouldn't wantobjto be indexable with allstrings, justkeyitself.key.No baseline changes or issues in the top 200.
We saw a slight bit of slowdown in compiler-unions.