-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed types of properties of contextual filtering mapped types (#56201)
- Loading branch information
Showing
4 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//// [tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts] //// | ||
|
||
=== contextualPropertyOfGenericFilteringMappedType.ts === | ||
declare function f1<T extends object>( | ||
>f1 : Symbol(f1, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 20)) | ||
|
||
data: T, | ||
>data : Symbol(data, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 38)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 20)) | ||
|
||
handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void }, | ||
>handlers : Symbol(handlers, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 1, 10)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 15)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 20)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 15)) | ||
>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 36)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 20)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 15)) | ||
>prop : Symbol(prop, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 48)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 2, 15)) | ||
|
||
): void; | ||
|
||
f1( | ||
>f1 : Symbol(f1, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 0, 0)) | ||
{ | ||
foo: 0, | ||
>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 6, 3)) | ||
|
||
bar: "", | ||
>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 7, 11)) | ||
|
||
}, | ||
{ | ||
foo: (value, key) => {}, | ||
>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 10, 3)) | ||
>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 11, 10)) | ||
>key : Symbol(key, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 11, 16)) | ||
|
||
bar: (value, key) => {}, | ||
>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 11, 28)) | ||
>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 12, 10)) | ||
>key : Symbol(key, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 12, 16)) | ||
|
||
}, | ||
); | ||
|
||
declare function f2<T extends object>( | ||
>f2 : Symbol(f2, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 14, 2)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 20)) | ||
|
||
data: T, | ||
>data : Symbol(data, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 38)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 20)) | ||
|
||
handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void }, | ||
>handlers : Symbol(handlers, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 17, 10)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 15)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 20)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 20)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 15)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 15)) | ||
>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 66)) | ||
>T : Symbol(T, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 16, 20)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 15)) | ||
>prop : Symbol(prop, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 78)) | ||
>P : Symbol(P, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 18, 15)) | ||
|
||
): void; | ||
|
||
f2( | ||
>f2 : Symbol(f2, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 14, 2)) | ||
{ | ||
foo: 0, | ||
>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 22, 3)) | ||
|
||
bar: "", | ||
>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 23, 11)) | ||
|
||
}, | ||
{ | ||
bar: (value, key) => {}, | ||
>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 26, 3)) | ||
>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 27, 10)) | ||
>key : Symbol(key, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 27, 16)) | ||
|
||
}, | ||
); | ||
|
127 changes: 127 additions & 0 deletions
127
tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
//// [tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts] //// | ||
|
||
=== contextualPropertyOfGenericFilteringMappedType.ts === | ||
declare function f1<T extends object>( | ||
>f1 : <T extends object>(data: T, handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void; }) => void | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ | ||
|
||
data: T, | ||
>data : T | ||
> : ^ | ||
|
||
handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void }, | ||
>handlers : { [P in keyof T as P]: (value: T[P], prop: P) => void; } | ||
> : ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^ ^^^ | ||
>value : T[P] | ||
> : ^^^^ | ||
>prop : P | ||
> : ^ | ||
|
||
): void; | ||
|
||
f1( | ||
>f1( { foo: 0, bar: "", }, { foo: (value, key) => {}, bar: (value, key) => {}, },) : void | ||
> : ^^^^ | ||
>f1 : <T extends object>(data: T, handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void; }) => void | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ | ||
{ | ||
>{ foo: 0, bar: "", } : { foo: number; bar: string; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
foo: 0, | ||
>foo : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
bar: "", | ||
>bar : string | ||
> : ^^^^^^ | ||
>"" : "" | ||
> : ^^ | ||
|
||
}, | ||
{ | ||
>{ foo: (value, key) => {}, bar: (value, key) => {}, } : { foo: (value: number, key: "foo") => void; bar: (value: string, key: "bar") => void; } | ||
> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ | ||
|
||
foo: (value, key) => {}, | ||
>foo : (value: number, key: "foo") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>(value, key) => {} : (value: number, key: "foo") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>value : number | ||
> : ^^^^^^ | ||
>key : "foo" | ||
> : ^^^^^ | ||
|
||
bar: (value, key) => {}, | ||
>bar : (value: string, key: "bar") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>(value, key) => {} : (value: string, key: "bar") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>value : string | ||
> : ^^^^^^ | ||
>key : "bar" | ||
> : ^^^^^ | ||
|
||
}, | ||
); | ||
|
||
declare function f2<T extends object>( | ||
>f2 : <T extends object>(data: T, handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void; }) => void | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ | ||
|
||
data: T, | ||
>data : T | ||
> : ^ | ||
|
||
handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void }, | ||
>handlers : { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void; } | ||
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^ ^^^ | ||
>value : T[P] | ||
> : ^^^^ | ||
>prop : P | ||
> : ^ | ||
|
||
): void; | ||
|
||
f2( | ||
>f2( { foo: 0, bar: "", }, { bar: (value, key) => {}, },) : void | ||
> : ^^^^ | ||
>f2 : <T extends object>(data: T, handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void; }) => void | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ | ||
{ | ||
>{ foo: 0, bar: "", } : { foo: number; bar: string; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
foo: 0, | ||
>foo : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
bar: "", | ||
>bar : string | ||
> : ^^^^^^ | ||
>"" : "" | ||
> : ^^ | ||
|
||
}, | ||
{ | ||
>{ bar: (value, key) => {}, } : { bar: (value: string, key: "bar") => void; } | ||
> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ | ||
|
||
bar: (value, key) => {}, | ||
>bar : (value: string, key: "bar") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>(value, key) => {} : (value: string, key: "bar") => void | ||
> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ | ||
>value : string | ||
> : ^^^^^^ | ||
>key : "bar" | ||
> : ^^^^^ | ||
|
||
}, | ||
); | ||
|
33 changes: 33 additions & 0 deletions
33
tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
declare function f1<T extends object>( | ||
data: T, | ||
handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void }, | ||
): void; | ||
|
||
f1( | ||
{ | ||
foo: 0, | ||
bar: "", | ||
}, | ||
{ | ||
foo: (value, key) => {}, | ||
bar: (value, key) => {}, | ||
}, | ||
); | ||
|
||
declare function f2<T extends object>( | ||
data: T, | ||
handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void }, | ||
): void; | ||
|
||
f2( | ||
{ | ||
foo: 0, | ||
bar: "", | ||
}, | ||
{ | ||
bar: (value, key) => {}, | ||
}, | ||
); |