diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 408739f480..f9ef54cd36 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8525,16 +8525,9 @@ namespace ts { } } else if (target.flags & TypeFlags.IndexedAccess) { - // if we have indexed access types with identical index types, see if relationship holds for - // the two object types. - if (source.flags & TypeFlags.IndexedAccess && (source).indexType === (target).indexType) { - if (result = isRelatedTo((source).objectType, (target).objectType, reportErrors)) { - return result; - } - } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. - const constraint = getBaseConstraintOfType(target); + const constraint = getConstraintOfType(target); if (constraint) { if (result = isRelatedTo(source, constraint, reportErrors)) { errorInfo = saveErrorInfo; @@ -8581,6 +8574,13 @@ namespace ts { return result; } } + else if (target.flags & TypeFlags.IndexedAccess && (source).indexType === (target).indexType) { + // if we have indexed access types with identical index types, see if relationship holds for + // the two object types. + if (result = isRelatedTo((source).objectType, (target).objectType, reportErrors)) { + return result; + } + } } else { if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (source).target === (target).target) { diff --git a/tests/baselines/reference/indexedAccessRelation.js b/tests/baselines/reference/indexedAccessRelation.js new file mode 100644 index 0000000000..c58c214e69 --- /dev/null +++ b/tests/baselines/reference/indexedAccessRelation.js @@ -0,0 +1,56 @@ +//// [indexedAccessRelation.ts] +// Repro from #14723 + +class Component { + setState(state: Pick) {} +} + +export interface State { + a?: T; +} + +class Foo {} + +class Comp extends Component> +{ + foo(a: T) { + this.setState({ a: a }); + } +} + + +//// [indexedAccessRelation.js] +// Repro from #14723 +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Component = (function () { + function Component() { + } + Component.prototype.setState = function (state) { }; + return Component; +}()); +var Foo = (function () { + function Foo() { + } + return Foo; +}()); +var Comp = (function (_super) { + __extends(Comp, _super); + function Comp() { + return _super !== null && _super.apply(this, arguments) || this; + } + Comp.prototype.foo = function (a) { + this.setState({ a: a }); + }; + return Comp; +}(Component)); diff --git a/tests/baselines/reference/indexedAccessRelation.symbols b/tests/baselines/reference/indexedAccessRelation.symbols new file mode 100644 index 0000000000..40fa52652f --- /dev/null +++ b/tests/baselines/reference/indexedAccessRelation.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/indexedAccessRelation.ts === +// Repro from #14723 + +class Component { +>Component : Symbol(Component, Decl(indexedAccessRelation.ts, 0, 0)) +>S : Symbol(S, Decl(indexedAccessRelation.ts, 2, 16)) + + setState(state: Pick) {} +>setState : Symbol(Component.setState, Decl(indexedAccessRelation.ts, 2, 20)) +>K : Symbol(K, Decl(indexedAccessRelation.ts, 3, 13)) +>S : Symbol(S, Decl(indexedAccessRelation.ts, 2, 16)) +>state : Symbol(state, Decl(indexedAccessRelation.ts, 3, 32)) +>Pick : Symbol(Pick, Decl(lib.d.ts, --, --)) +>S : Symbol(S, Decl(indexedAccessRelation.ts, 2, 16)) +>K : Symbol(K, Decl(indexedAccessRelation.ts, 3, 13)) +} + +export interface State { +>State : Symbol(State, Decl(indexedAccessRelation.ts, 4, 1)) +>T : Symbol(T, Decl(indexedAccessRelation.ts, 6, 23)) + + a?: T; +>a : Symbol(State.a, Decl(indexedAccessRelation.ts, 6, 27)) +>T : Symbol(T, Decl(indexedAccessRelation.ts, 6, 23)) +} + +class Foo {} +>Foo : Symbol(Foo, Decl(indexedAccessRelation.ts, 8, 1)) + +class Comp extends Component> +>Comp : Symbol(Comp, Decl(indexedAccessRelation.ts, 10, 12)) +>T : Symbol(T, Decl(indexedAccessRelation.ts, 12, 11)) +>Foo : Symbol(Foo, Decl(indexedAccessRelation.ts, 8, 1)) +>S : Symbol(S, Decl(indexedAccessRelation.ts, 12, 25)) +>Component : Symbol(Component, Decl(indexedAccessRelation.ts, 0, 0)) +>S : Symbol(S, Decl(indexedAccessRelation.ts, 12, 25)) +>State : Symbol(State, Decl(indexedAccessRelation.ts, 4, 1)) +>T : Symbol(T, Decl(indexedAccessRelation.ts, 12, 11)) +{ + foo(a: T) { +>foo : Symbol(Comp.foo, Decl(indexedAccessRelation.ts, 13, 1)) +>a : Symbol(a, Decl(indexedAccessRelation.ts, 14, 8)) +>T : Symbol(T, Decl(indexedAccessRelation.ts, 12, 11)) + + this.setState({ a: a }); +>this.setState : Symbol(Component.setState, Decl(indexedAccessRelation.ts, 2, 20)) +>this : Symbol(Comp, Decl(indexedAccessRelation.ts, 10, 12)) +>setState : Symbol(Component.setState, Decl(indexedAccessRelation.ts, 2, 20)) +>a : Symbol(a, Decl(indexedAccessRelation.ts, 15, 23)) +>a : Symbol(a, Decl(indexedAccessRelation.ts, 14, 8)) + } +} + diff --git a/tests/baselines/reference/indexedAccessRelation.types b/tests/baselines/reference/indexedAccessRelation.types new file mode 100644 index 0000000000..2564a82702 --- /dev/null +++ b/tests/baselines/reference/indexedAccessRelation.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/indexedAccessRelation.ts === +// Repro from #14723 + +class Component { +>Component : Component +>S : S + + setState(state: Pick) {} +>setState : (state: Pick) => void +>K : K +>S : S +>state : Pick +>Pick : Pick +>S : S +>K : K +} + +export interface State { +>State : State +>T : T + + a?: T; +>a : T +>T : T +} + +class Foo {} +>Foo : Foo + +class Comp extends Component> +>Comp : Comp +>T : T +>Foo : Foo +>S : S +>Component : Component> +>S : S +>State : State +>T : T +{ + foo(a: T) { +>foo : (a: T) => void +>a : T +>T : T + + this.setState({ a: a }); +>this.setState({ a: a }) : void +>this.setState : )>(state: Pick, K>) => void +>this : this +>setState : )>(state: Pick, K>) => void +>{ a: a } : { a: T; } +>a : T +>a : T + } +} + diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index bc26bb272f..ec2bacbe66 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -1,39 +1,71 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. Type 'T[string]' is not assignable to type 'U[keyof T]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[keyof T]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T[string]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[K]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,5): error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. Type 'T[string]' is not assignable to type 'U[keyof U]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[keyof U]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T[string]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[K]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. Type 'undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[string]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(36,5): error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. Type 'undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[string]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. Type 'undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[string]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(42,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'. Type 'T[string]' is not assignable to type 'U[keyof T]'. - Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. - Type 'T[string]' is not assignable to type 'U[keyof T]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T[string]' is not assignable to type 'U[keyof T]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[keyof T]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. Type 'undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[string]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(47,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. Type 'T[string]' is not assignable to type 'U[K] | undefined'. Type 'T[string]' is not assignable to type 'U[K]'. - Type 'T[K]' is not assignable to type 'U[K]'. - Type 'T[string]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T[string]' is not assignable to type 'U[K]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[K]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(52,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly' only permits reading. @@ -44,7 +76,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(126,5): error TS tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(142,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. Type 'T[string]' is not assignable to type 'U[P]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[P]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(147,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. Type 'keyof U' is not assignable to type 'keyof T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(152,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: T[P]; }'. @@ -56,7 +92,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(162,5): error TS tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in K]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. Type 'T[string]' is not assignable to type 'U[P]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. + Type 'T[P]' is not assignable to type 'U[string]'. + Type 'T[string]' is not assignable to type 'U[string]'. + Type 'T' is not assignable to type 'U'. ==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (27 errors) ==== @@ -75,7 +115,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f4(x: T, y: U, k: K) { @@ -84,7 +128,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f5(x: T, y: U, k: keyof U) { @@ -95,7 +143,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof U]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. } @@ -108,7 +160,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. } @@ -118,6 +174,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. !!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[string]'. y[k] = x[k]; } @@ -126,6 +183,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. !!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[string]'. y[k] = x[k]; } @@ -134,14 +192,21 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. !!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[string]'. y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f13(x: T, y: Partial, k: K) { @@ -149,14 +214,21 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~~~~ !!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. !!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[string]'. y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f20(x: T, y: Readonly, k: keyof T) { @@ -270,7 +342,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS !!! error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. !!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f72(x: { [P in keyof T]: T[P] }, y: { [P in keyof U]: U[P] }) { @@ -312,6 +388,10 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS !!! error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in K]: U[P]; }'. !!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'. !!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } \ No newline at end of file diff --git a/tests/cases/compiler/indexedAccessRelation.ts b/tests/cases/compiler/indexedAccessRelation.ts new file mode 100644 index 0000000000..ccfcd559e2 --- /dev/null +++ b/tests/cases/compiler/indexedAccessRelation.ts @@ -0,0 +1,18 @@ +// Repro from #14723 + +class Component { + setState(state: Pick) {} +} + +export interface State { + a?: T; +} + +class Foo {} + +class Comp extends Component> +{ + foo(a: T) { + this.setState({ a: a }); + } +}