-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Description
π Search Terms
"homomorphic" "keyof" "extends"
π Version & Regression Information
- This changed between versions 3.8.3 and 3.9.7
β― Playground Link
π» Code
type KeyMap<T> = keyof T extends PropertyKey ? { [K in keyof T]: K } : never;
type X = KeyMap<number>;π Actual behavior
X is evaluated to
type X = {
toString: "toString";
toFixed: "toFixed";
toExponential: "toExponential";
toPrecision: "toPrecision";
valueOf: "valueOf";
toLocaleString: "toLocaleString";
}π Expected behavior
X should be evaluated to number because according to the FAQ,
Mapped types declared as
{ [ K in keyof T ]: U }where T is a type parameter are known ashomomorphic mapped types, which means that the mapped type is a structure preserving function ofT. When type parameterTis instantiated with a primitive type the mapped type evaluates to the same primitive.
Additional information about the issue
Replacing PropertyKey with either unknown or any fixes the issue for some reason.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels