-
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.
Merge pull request #19319 from Microsoft/fixMappedTypeInferenceErrors
Fix mapped type inference errors
- Loading branch information
Showing
8 changed files
with
229 additions
and
12 deletions.
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
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
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
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/mappedTypeInferenceErrors.errors.txt
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,44 @@ | ||
tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts(9,5): error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: number; baz: {}; }>'. | ||
Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; }'. | ||
Types of property 'computed' are incompatible. | ||
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'. | ||
Types of property 'baz' are incompatible. | ||
Type 'number' is not assignable to type '() => {}'. | ||
|
||
|
||
==== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts (1 errors) ==== | ||
// Repro from #19316 | ||
|
||
type ComputedOf<T> = { | ||
[K in keyof T]: () => T[K]; | ||
} | ||
|
||
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; | ||
|
||
foo({ | ||
~ | ||
props: { x: 10, y: 20 }, | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
computed: { | ||
~~~~~~~~~~~~~~~ | ||
bar(): number { | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
let z = this.bar; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
return 42; | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
}, | ||
~~~~~~~~~~ | ||
baz: 42 | ||
~~~~~~~~~~~~~~~ | ||
} | ||
~~~~~ | ||
}); | ||
~ | ||
!!! error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: number; baz: {}; }>'. | ||
!!! error TS2345: Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; }'. | ||
!!! error TS2345: Types of property 'computed' are incompatible. | ||
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'. | ||
!!! error TS2345: Types of property 'baz' are incompatible. | ||
!!! error TS2345: Type 'number' is not assignable to type '() => {}'. | ||
|
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,34 @@ | ||
//// [mappedTypeInferenceErrors.ts] | ||
// Repro from #19316 | ||
|
||
type ComputedOf<T> = { | ||
[K in keyof T]: () => T[K]; | ||
} | ||
|
||
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; | ||
|
||
foo({ | ||
props: { x: 10, y: 20 }, | ||
computed: { | ||
bar(): number { | ||
let z = this.bar; | ||
return 42; | ||
}, | ||
baz: 42 | ||
} | ||
}); | ||
|
||
|
||
//// [mappedTypeInferenceErrors.js] | ||
"use strict"; | ||
// Repro from #19316 | ||
foo({ | ||
props: { x: 10, y: 20 }, | ||
computed: { | ||
bar: function () { | ||
var z = this.bar; | ||
return 42; | ||
}, | ||
baz: 42 | ||
} | ||
}); |
55 changes: 55 additions & 0 deletions
55
tests/baselines/reference/mappedTypeInferenceErrors.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,55 @@ | ||
=== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts === | ||
// Repro from #19316 | ||
|
||
type ComputedOf<T> = { | ||
>ComputedOf : Symbol(ComputedOf, Decl(mappedTypeInferenceErrors.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16)) | ||
|
||
[K in keyof T]: () => T[K]; | ||
>K : Symbol(K, Decl(mappedTypeInferenceErrors.ts, 3, 5)) | ||
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16)) | ||
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16)) | ||
>K : Symbol(K, Decl(mappedTypeInferenceErrors.ts, 3, 5)) | ||
} | ||
|
||
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; | ||
>foo : Symbol(foo, Decl(mappedTypeInferenceErrors.ts, 4, 1)) | ||
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21)) | ||
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23)) | ||
>options : Symbol(options, Decl(mappedTypeInferenceErrors.ts, 6, 27)) | ||
>props : Symbol(props, Decl(mappedTypeInferenceErrors.ts, 6, 37)) | ||
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21)) | ||
>computed : Symbol(computed, Decl(mappedTypeInferenceErrors.ts, 6, 47)) | ||
>ComputedOf : Symbol(ComputedOf, Decl(mappedTypeInferenceErrors.ts, 0, 0)) | ||
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23)) | ||
>ThisType : Symbol(ThisType, Decl(lib.d.ts, --, --)) | ||
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21)) | ||
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23)) | ||
|
||
foo({ | ||
>foo : Symbol(foo, Decl(mappedTypeInferenceErrors.ts, 4, 1)) | ||
|
||
props: { x: 10, y: 20 }, | ||
>props : Symbol(props, Decl(mappedTypeInferenceErrors.ts, 8, 5)) | ||
>x : Symbol(x, Decl(mappedTypeInferenceErrors.ts, 9, 12)) | ||
>y : Symbol(y, Decl(mappedTypeInferenceErrors.ts, 9, 19)) | ||
|
||
computed: { | ||
>computed : Symbol(computed, Decl(mappedTypeInferenceErrors.ts, 9, 28)) | ||
|
||
bar(): number { | ||
>bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15)) | ||
|
||
let z = this.bar; | ||
>z : Symbol(z, Decl(mappedTypeInferenceErrors.ts, 12, 15)) | ||
>this.bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15)) | ||
>this : Symbol(__object, Decl(mappedTypeInferenceErrors.ts, 10, 13)) | ||
>bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15)) | ||
|
||
return 42; | ||
}, | ||
baz: 42 | ||
>baz : Symbol(baz, Decl(mappedTypeInferenceErrors.ts, 14, 10)) | ||
} | ||
}); | ||
|
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,64 @@ | ||
=== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts === | ||
// Repro from #19316 | ||
|
||
type ComputedOf<T> = { | ||
>ComputedOf : ComputedOf<T> | ||
>T : T | ||
|
||
[K in keyof T]: () => T[K]; | ||
>K : K | ||
>T : T | ||
>T : T | ||
>K : K | ||
} | ||
|
||
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; | ||
>foo : <P, C>(options: { props: P; computed: ComputedOf<C>; } & ThisType<P & C>) => void | ||
>P : P | ||
>C : C | ||
>options : { props: P; computed: ComputedOf<C>; } & ThisType<P & C> | ||
>props : P | ||
>P : P | ||
>computed : ComputedOf<C> | ||
>ComputedOf : ComputedOf<T> | ||
>C : C | ||
>ThisType : ThisType<T> | ||
>P : P | ||
>C : C | ||
|
||
foo({ | ||
>foo({ props: { x: 10, y: 20 }, computed: { bar(): number { let z = this.bar; return 42; }, baz: 42 }}) : any | ||
>foo : <P, C>(options: { props: P; computed: ComputedOf<C>; } & ThisType<P & C>) => void | ||
>{ props: { x: 10, y: 20 }, computed: { bar(): number { let z = this.bar; return 42; }, baz: 42 }} : { props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; } | ||
|
||
props: { x: 10, y: 20 }, | ||
>props : { x: number; y: number; } | ||
>{ x: 10, y: 20 } : { x: number; y: number; } | ||
>x : number | ||
>10 : 10 | ||
>y : number | ||
>20 : 20 | ||
|
||
computed: { | ||
>computed : { bar(): number; baz: number; } | ||
>{ bar(): number { let z = this.bar; return 42; }, baz: 42 } : { bar(): number; baz: number; } | ||
|
||
bar(): number { | ||
>bar : () => number | ||
|
||
let z = this.bar; | ||
>z : () => number | ||
>this.bar : () => number | ||
>this : { bar(): number; baz: number; } | ||
>bar : () => number | ||
|
||
return 42; | ||
>42 : 42 | ||
|
||
}, | ||
baz: 42 | ||
>baz : number | ||
>42 : 42 | ||
} | ||
}); | ||
|
20 changes: 20 additions & 0 deletions
20
tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.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,20 @@ | ||
// @strict: true | ||
|
||
// Repro from #19316 | ||
|
||
type ComputedOf<T> = { | ||
[K in keyof T]: () => T[K]; | ||
} | ||
|
||
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; | ||
|
||
foo({ | ||
props: { x: 10, y: 20 }, | ||
computed: { | ||
bar(): number { | ||
let z = this.bar; | ||
return 42; | ||
}, | ||
baz: 42 | ||
} | ||
}); |