Merge pull request #14874 from Microsoft/fixIndexedAccessRelation

Fix stack overflow in indexed access relation
This commit is contained in:
Anders Hejlsberg 2017-03-28 06:19:59 +02:00 committed by GitHub
commit 1ae5bef80d
6 changed files with 294 additions and 32 deletions

View file

@ -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 && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>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(<IndexedAccessType>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 && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
// if we have indexed access types with identical index types, see if relationship holds for
// the two object types.
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
return result;
}
}
}
else {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {

View file

@ -0,0 +1,56 @@
//// [indexedAccessRelation.ts]
// Repro from #14723
class Component<S> {
setState<K extends keyof S>(state: Pick<S, K>) {}
}
export interface State<T> {
a?: T;
}
class Foo {}
class Comp<T extends Foo, S> extends Component<S & State<T>>
{
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));

View file

@ -0,0 +1,53 @@
=== tests/cases/compiler/indexedAccessRelation.ts ===
// Repro from #14723
class Component<S> {
>Component : Symbol(Component, Decl(indexedAccessRelation.ts, 0, 0))
>S : Symbol(S, Decl(indexedAccessRelation.ts, 2, 16))
setState<K extends keyof S>(state: Pick<S, K>) {}
>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<T> {
>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<T extends Foo, S> extends Component<S & State<T>>
>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))
}
}

View file

@ -0,0 +1,55 @@
=== tests/cases/compiler/indexedAccessRelation.ts ===
// Repro from #14723
class Component<S> {
>Component : Component<S>
>S : S
setState<K extends keyof S>(state: Pick<S, K>) {}
>setState : <K extends keyof S>(state: Pick<S, K>) => void
>K : K
>S : S
>state : Pick<S, K>
>Pick : Pick<T, K>
>S : S
>K : K
}
export interface State<T> {
>State : State<T>
>T : T
a?: T;
>a : T
>T : T
}
class Foo {}
>Foo : Foo
class Comp<T extends Foo, S> extends Component<S & State<T>>
>Comp : Comp<T, S>
>T : T
>Foo : Foo
>S : S
>Component : Component<S & State<T>>
>S : S
>State : State<T>
>T : T
{
foo(a: T) {
>foo : (a: T) => void
>a : T
>T : T
this.setState({ a: a });
>this.setState({ a: a }) : void
>this.setState : <K extends keyof (S & State<T>)>(state: Pick<S & State<T>, K>) => void
>this : this
>setState : <K extends keyof (S & State<T>)>(state: Pick<S & State<T>, K>) => void
>{ a: a } : { a: T; }
>a : T
>a : T
}
}

View file

@ -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<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly<U>' 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<T, U extends T, K extends keyof T>(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<T, U extends T>(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<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, 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<T>(x: T, y: Readonly<T>, 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<T, U extends T>(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'.
}

View file

@ -0,0 +1,18 @@
// Repro from #14723
class Component<S> {
setState<K extends keyof S>(state: Pick<S, K>) {}
}
export interface State<T> {
a?: T;
}
class Foo {}
class Comp<T extends Foo, S> extends Component<S & State<T>>
{
foo(a: T) {
this.setState({ a: a });
}
}