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
constobj={A: 1,B: 1};// Ignore the implementation, it's about the inferred return type of the function, which should be "A" | "B"constgetRandomKey=()=>Math.random()>0.5 ? "A" : "B"typeFoo=ReturnType<typeofgetRandomKey>extendskeyoftypeofobj ? ReturnType<typeofgetRandomKey> : never;constrandomKey=getRandomKey();constcasted: Foo=getRandomKey();constrandomKeyResult=obj[randomKey];constcastedResult=obj[casted];
π Actual behavior
randomKeyResult has type 'number', but castedResult has type any
π Expected behavior
Both randomKeyResult and castedResult should be type number.
If you look at the type of casted and randomKey, the types are identical: "A" | "B". Yet when using them to access a property, they behave differently. Note that in 4.2.3, this expected behavior was also the actual behavior.
The text was updated successfully, but these errors were encountered:
looks like something changed in newer version where they are interpreting this line outputs differently type Foo = ReturnType<typeof getRandomKey> extends keyof typeof obj ? ReturnType<typeof getRandomKey> : never;
if I change this to type Foo = ReturnType<typeof getRandomKey>;
type of casted and randomKey both are numbers.
OR
if i type cast it at access time type t = ReturnType1<typeof getRandomKey>; const castedResult = obj[casted as t];
Bug Report
π Search Terms
implicit any, property access
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
randomKeyResult
has type 'number', butcastedResult
has typeany
π Expected behavior
Both
randomKeyResult
andcastedResult
should be typenumber
.If you look at the type of
casted
andrandomKey
, the types are identical:"A" | "B"
. Yet when using them to access a property, they behave differently. Note that in 4.2.3, this expected behavior was also the actual behavior.The text was updated successfully, but these errors were encountered: