Skip to content

Commit 4b4211f

Browse files
committed
Add repro
1 parent 3fb3649 commit 4b4211f

File tree

4 files changed

+347
-0
lines changed

4 files changed

+347
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//// [indexedAccessTypeConstraints.ts]
2+
3+
// Repro from #14557
4+
5+
interface IData<T> {
6+
content: T;
7+
}
8+
9+
type Data<T> = {
10+
get: <K extends keyof T>(prop: K) => T[K];
11+
};
12+
13+
class Parent<M> {
14+
private data: Data<M>;
15+
getData(): Data<M> {
16+
return this.data;
17+
}
18+
}
19+
20+
export class Foo<C> extends Parent<IData<C>> {
21+
getContent(): C {
22+
return this.getData().get('content');
23+
}
24+
}
25+
26+
export class Bar<C, T extends IData<C>> extends Parent<T> {
27+
getContent(): C {
28+
return this.getData().get('content');
29+
}
30+
}
31+
32+
// Repro from #14557
33+
34+
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
35+
x = y;
36+
}
37+
38+
39+
//// [indexedAccessTypeConstraints.js]
40+
// Repro from #14557
41+
"use strict";
42+
var __extends = (this && this.__extends) || (function () {
43+
var extendStatics = Object.setPrototypeOf ||
44+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
45+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
46+
return function (d, b) {
47+
extendStatics(d, b);
48+
function __() { this.constructor = d; }
49+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
50+
};
51+
})();
52+
exports.__esModule = true;
53+
var Parent = (function () {
54+
function Parent() {
55+
}
56+
Parent.prototype.getData = function () {
57+
return this.data;
58+
};
59+
return Parent;
60+
}());
61+
var Foo = (function (_super) {
62+
__extends(Foo, _super);
63+
function Foo() {
64+
return _super !== null && _super.apply(this, arguments) || this;
65+
}
66+
Foo.prototype.getContent = function () {
67+
return this.getData().get('content');
68+
};
69+
return Foo;
70+
}(Parent));
71+
exports.Foo = Foo;
72+
var Bar = (function (_super) {
73+
__extends(Bar, _super);
74+
function Bar() {
75+
return _super !== null && _super.apply(this, arguments) || this;
76+
}
77+
Bar.prototype.getContent = function () {
78+
return this.getData().get('content');
79+
};
80+
return Bar;
81+
}(Parent));
82+
exports.Bar = Bar;
83+
// Repro from #14557
84+
function foo(x, y) {
85+
x = y;
86+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
=== tests/cases/compiler/indexedAccessTypeConstraints.ts ===
2+
3+
// Repro from #14557
4+
5+
interface IData<T> {
6+
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
7+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16))
8+
9+
content: T;
10+
>content : Symbol(IData.content, Decl(indexedAccessTypeConstraints.ts, 3, 20))
11+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16))
12+
}
13+
14+
type Data<T> = {
15+
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
16+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
17+
18+
get: <K extends keyof T>(prop: K) => T[K];
19+
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
20+
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
21+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
22+
>prop : Symbol(prop, Decl(indexedAccessTypeConstraints.ts, 8, 29))
23+
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
24+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
25+
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
26+
27+
};
28+
29+
class Parent<M> {
30+
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
31+
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
32+
33+
private data: Data<M>;
34+
>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
35+
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
36+
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
37+
38+
getData(): Data<M> {
39+
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
40+
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
41+
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
42+
43+
return this.data;
44+
>this.data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
45+
>this : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
46+
>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
47+
}
48+
}
49+
50+
export class Foo<C> extends Parent<IData<C>> {
51+
>Foo : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1))
52+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
53+
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
54+
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
55+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
56+
57+
getContent(): C {
58+
>getContent : Symbol(Foo.getContent, Decl(indexedAccessTypeConstraints.ts, 18, 46))
59+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
60+
61+
return this.getData().get('content');
62+
>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
63+
>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
64+
>this : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1))
65+
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
66+
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
67+
}
68+
}
69+
70+
export class Bar<C, T extends IData<C>> extends Parent<T> {
71+
>Bar : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1))
72+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
73+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19))
74+
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
75+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
76+
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
77+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19))
78+
79+
getContent(): C {
80+
>getContent : Symbol(Bar.getContent, Decl(indexedAccessTypeConstraints.ts, 24, 59))
81+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
82+
83+
return this.getData().get('content');
84+
>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
85+
>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
86+
>this : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1))
87+
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
88+
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
89+
}
90+
}
91+
92+
// Repro from #14557
93+
94+
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
95+
>foo : Symbol(foo, Decl(indexedAccessTypeConstraints.ts, 28, 1))
96+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
97+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15))
98+
>content : Symbol(content, Decl(indexedAccessTypeConstraints.ts, 32, 27))
99+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
100+
>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42))
101+
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
102+
>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47))
103+
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15))
104+
105+
x = y;
106+
>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42))
107+
>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47))
108+
}
109+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
=== tests/cases/compiler/indexedAccessTypeConstraints.ts ===
2+
3+
// Repro from #14557
4+
5+
interface IData<T> {
6+
>IData : IData<T>
7+
>T : T
8+
9+
content: T;
10+
>content : T
11+
>T : T
12+
}
13+
14+
type Data<T> = {
15+
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
16+
>T : T
17+
18+
get: <K extends keyof T>(prop: K) => T[K];
19+
>get : <K extends keyof T>(prop: K) => T[K]
20+
>K : K
21+
>T : T
22+
>prop : K
23+
>K : K
24+
>T : T
25+
>K : K
26+
27+
};
28+
29+
class Parent<M> {
30+
>Parent : Parent<M>
31+
>M : M
32+
33+
private data: Data<M>;
34+
>data : { get: <K extends keyof M>(prop: K) => M[K]; }
35+
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
36+
>M : M
37+
38+
getData(): Data<M> {
39+
>getData : () => { get: <K extends keyof M>(prop: K) => M[K]; }
40+
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
41+
>M : M
42+
43+
return this.data;
44+
>this.data : { get: <K extends keyof M>(prop: K) => M[K]; }
45+
>this : this
46+
>data : { get: <K extends keyof M>(prop: K) => M[K]; }
47+
}
48+
}
49+
50+
export class Foo<C> extends Parent<IData<C>> {
51+
>Foo : Foo<C>
52+
>C : C
53+
>Parent : Parent<IData<C>>
54+
>IData : IData<T>
55+
>C : C
56+
57+
getContent(): C {
58+
>getContent : () => C
59+
>C : C
60+
61+
return this.getData().get('content');
62+
>this.getData().get('content') : C
63+
>this.getData().get : <K extends "content">(prop: K) => IData<C>[K]
64+
>this.getData() : { get: <K extends "content">(prop: K) => IData<C>[K]; }
65+
>this.getData : () => { get: <K extends "content">(prop: K) => IData<C>[K]; }
66+
>this : this
67+
>getData : () => { get: <K extends "content">(prop: K) => IData<C>[K]; }
68+
>get : <K extends "content">(prop: K) => IData<C>[K]
69+
>'content' : "content"
70+
}
71+
}
72+
73+
export class Bar<C, T extends IData<C>> extends Parent<T> {
74+
>Bar : Bar<C, T>
75+
>C : C
76+
>T : T
77+
>IData : IData<T>
78+
>C : C
79+
>Parent : Parent<T>
80+
>T : T
81+
82+
getContent(): C {
83+
>getContent : () => C
84+
>C : C
85+
86+
return this.getData().get('content');
87+
>this.getData().get('content') : T["content"]
88+
>this.getData().get : <K extends keyof T>(prop: K) => T[K]
89+
>this.getData() : { get: <K extends keyof T>(prop: K) => T[K]; }
90+
>this.getData : () => { get: <K extends keyof T>(prop: K) => T[K]; }
91+
>this : this
92+
>getData : () => { get: <K extends keyof T>(prop: K) => T[K]; }
93+
>get : <K extends keyof T>(prop: K) => T[K]
94+
>'content' : "content"
95+
}
96+
}
97+
98+
// Repro from #14557
99+
100+
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
101+
>foo : <C, T extends { content: C; }>(x: C, y: T["content"]) => void
102+
>C : C
103+
>T : T
104+
>content : C
105+
>C : C
106+
>x : C
107+
>C : C
108+
>y : T["content"]
109+
>T : T
110+
111+
x = y;
112+
>x = y : T["content"]
113+
>x : C
114+
>y : T["content"]
115+
}
116+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @strict: true
2+
3+
// Repro from #14557
4+
5+
interface IData<T> {
6+
content: T;
7+
}
8+
9+
type Data<T> = {
10+
get: <K extends keyof T>(prop: K) => T[K];
11+
};
12+
13+
class Parent<M> {
14+
private data: Data<M>;
15+
getData(): Data<M> {
16+
return this.data;
17+
}
18+
}
19+
20+
export class Foo<C> extends Parent<IData<C>> {
21+
getContent(): C {
22+
return this.getData().get('content');
23+
}
24+
}
25+
26+
export class Bar<C, T extends IData<C>> extends Parent<T> {
27+
getContent(): C {
28+
return this.getData().get('content');
29+
}
30+
}
31+
32+
// Repro from #14557
33+
34+
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
35+
x = y;
36+
}

0 commit comments

Comments
 (0)