-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
π Search Terms
Function
Generic Type
Infer
String
Literal
Mapped Type
alias
π Version & Regression Information
This is a bug in the 4.7.x
version of TS.
β― Playground Link
Playground link with relevant code
π» Code
Using as
in Mapped Types seems to cause the value to be incorrectly inferred in the Literal Type of the value.
declare function foo1<T extends { [P in keyof T as Capitalize<P & string>]: V }, V extends string>(a: T): T;
declare function foo2<T extends { [P in keyof T & string as Capitalize<P>]: V }, V extends string>(a: T): T;
declare function foo3<T extends { [P in keyof T]: V }, V extends string>(a: T): T;
declare function foo4<T extends { [P in Capitalize<keyof T & string>]: V }, V extends string>(a: T): T;
export const r1 = foo1({A: "a"}); // TS4.6 { A: "a"; } | TS4.7 { A: string; }
export const r2 = foo2({A: "a"}); // TS4.6 { A: "a"; } | TS4.7 any -> 'r2' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
export const r3 = foo3({A: "a"}); // TS4.6 { A: "a"; } | TS4.7 { A: "a"; }
export const r4 = foo4({A: "a"}); // TS4.6 { A: "a"; } | TS4.7 { A: "a"; }
π Actual behavior
declare function foo1<T extends { [P in keyof T as Capitalize<P & string>]: V }, V extends string>(a: T): T;
declare function foo2<T extends { [P in keyof T & string as Capitalize<P>]: V }, V extends string>(a: T): T;
declare function foo3<T extends { [P in keyof T]: V }, V extends string>(a: T): T;
declare function foo4<T extends { [P in Capitalize<keyof T & string>]: V }, V extends string>(a: T): T;
export const r1 = foo1({A: "a"}); // β { A: string; }
export const r2 = foo2({A: "a"}); // β any -> 'r2' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
export const r3 = foo3({A: "a"}); // β
{ A: "a"; }
export const r4 = foo4({A: "a"}); // β
{ A: "a"; }
π Expected behavior
declare function foo1<T extends { [P in keyof T as Capitalize<P & string>]: V }, V extends string>(a: T): T;
declare function foo2<T extends { [P in keyof T & string as Capitalize<P>]: V }, V extends string>(a: T): T;
declare function foo3<T extends { [P in keyof T]: V }, V extends string>(a: T): T;
declare function foo4<T extends { [P in Capitalize<keyof T & string>]: V }, V extends string>(a: T): T;
export const r1 = foo1({A: "a"}); // β
{ A: "a"; }
export const r2 = foo2({A: "a"}); // β
{ A: "a"; }
export const r3 = foo3({A: "a"}); // β
{ A: "a"; }
export const r4 = foo4({A: "a"}); // β
{ A: "a"; }
whzx5byb
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug