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.
Mostly within the noise.
The text was updated successfully, but these errors were encountered:
The discussion about enum reverse mappings reads like an account of a game of tug-of-war, and then at the end nobody wins - the rope goes slack and both teams fall in the mud 😝
Preserving attributes on reference directives
#57681
preserve="true"
?.d.ts
bundlers?.d.ts
and get the same behavior.Reallowing
Infinity
,-Infinity
,NaN
as enum member namesBackground
#56161
#57845
enum E { "10" = 42 }
enum E { "10" = 42, yadda = 10 }
which breaks the reverse mapping.E[10]
maps toyadda
not42
Infinity
orNaN
enum 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 neitherobj
norkey
, 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.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.
obj
to be indexable.obj
to have the typeobject & Record<unique typeof key, unknown>
. Really wouldn't wantobj
to be indexable with allstring
s, justkey
itself.key
.No baseline changes or issues in the top 200.
We saw a slight bit of slowdown in compiler-unions.
The text was updated successfully, but these errors were encountered: