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
typeKeyIsFinite={[kin0|1|2]: k}typeKeyIsNum={[kinnumber]: k}// if KeyIsFinite[1]: 1 then this will be trueconstkeyIsFiniteTest: KeyIsFinite[1]extends1 ? true : false=true;// if KeyIsNum[1]: 1 then this will be true, but this is actually false, because in KeyIsNum, we are losing information about what `k` isconstkeyIsNumTest: KeyIsNum[1]extends1 ? true : false=true;// similarly, you can do this with stringstypeKeyIsFiniteStr={[kin'0'|'1'|'2']: k}typeKeyIsStr={[kinstring]: k}constkeyIsFiniteStrTest: KeyIsFiniteStr['1']extends'1' ? true : false=true;constkeyIsStrTest: KeyIsStr['1']extends'1' ? true : false=true;
🙁 Actual behavior
We see a type error informing us that keyIsNumTest has type false but is the value true, this is because KeyIsNum is not preserving information about k (I assume), and thus is saying that KeyIsNum[1] = number rather than KeyIsNum[1] = 1. We see that KeyIsFinite[1] = 1, so this appears to be an inconsistency.
🙂 Expected behavior
I would expect KeyIsNum to behave like KeyIsFinite and thus for KeyIsNum[1] = 1 rather than KeyIsNum[1] = number
The text was updated successfully, but these errors were encountered:
Strong duplicate energy but really just working as intended: mapped types over finite types produce object types with properties, but mapped types over infinite types produce index signatures. Different input different output.
@jcalz@RyanCavanaugh Yep, I think with "Here I expect string to behave as if it were the union of all possible string literal types." in #22509 this is likely a duplicate. I'd like to just promote that it'd be good for this to work for things like numbers too, but I'll close this in favour of that issue. Thanks!
Bug Report
🔎 Search Terms
key number string
type key loses
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
We see a type error informing us that
keyIsNumTest
has typefalse
but is the valuetrue
, this is becauseKeyIsNum
is not preserving information aboutk
(I assume), and thus is saying thatKeyIsNum[1] = number
rather thanKeyIsNum[1] = 1
. We see thatKeyIsFinite[1] = 1
, so this appears to be an inconsistency.🙂 Expected behavior
I would expect
KeyIsNum
to behave likeKeyIsFinite
and thus forKeyIsNum[1] = 1
rather thanKeyIsNum[1] = number
The text was updated successfully, but these errors were encountered: