Add repro

This commit is contained in:
Anders Hejlsberg
2017-03-09 11:57:56 -08:00
parent 3fb364981b
commit 4b4211f38b
4 changed files with 347 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
//// [indexedAccessTypeConstraints.ts]
// Repro from #14557
interface IData<T> {
content: T;
}
type Data<T> = {
get: <K extends keyof T>(prop: K) => T[K];
};
class Parent<M> {
private data: Data<M>;
getData(): Data<M> {
return this.data;
}
}
export class Foo<C> extends Parent<IData<C>> {
getContent(): C {
return this.getData().get('content');
}
}
export class Bar<C, T extends IData<C>> extends Parent<T> {
getContent(): C {
return this.getData().get('content');
}
}
// Repro from #14557
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
x = y;
}
//// [indexedAccessTypeConstraints.js]
// Repro from #14557
"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 Parent = (function () {
function Parent() {
}
Parent.prototype.getData = function () {
return this.data;
};
return Parent;
}());
var Foo = (function (_super) {
__extends(Foo, _super);
function Foo() {
return _super !== null && _super.apply(this, arguments) || this;
}
Foo.prototype.getContent = function () {
return this.getData().get('content');
};
return Foo;
}(Parent));
exports.Foo = Foo;
var Bar = (function (_super) {
__extends(Bar, _super);
function Bar() {
return _super !== null && _super.apply(this, arguments) || this;
}
Bar.prototype.getContent = function () {
return this.getData().get('content');
};
return Bar;
}(Parent));
exports.Bar = Bar;
// Repro from #14557
function foo(x, y) {
x = y;
}

View File

@@ -0,0 +1,109 @@
=== tests/cases/compiler/indexedAccessTypeConstraints.ts ===
// Repro from #14557
interface IData<T> {
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16))
content: T;
>content : Symbol(IData.content, Decl(indexedAccessTypeConstraints.ts, 3, 20))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16))
}
type Data<T> = {
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
get: <K extends keyof T>(prop: K) => T[K];
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
>prop : Symbol(prop, Decl(indexedAccessTypeConstraints.ts, 8, 29))
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10))
>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10))
};
class Parent<M> {
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
private data: Data<M>;
>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
getData(): Data<M> {
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1))
>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13))
return this.data;
>this.data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
>this : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17))
}
}
export class Foo<C> extends Parent<IData<C>> {
>Foo : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
getContent(): C {
>getContent : Symbol(Foo.getContent, Decl(indexedAccessTypeConstraints.ts, 18, 46))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17))
return this.getData().get('content');
>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
>this : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1))
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
}
}
export class Bar<C, T extends IData<C>> extends Parent<T> {
>Bar : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19))
>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19))
getContent(): C {
>getContent : Symbol(Bar.getContent, Decl(indexedAccessTypeConstraints.ts, 24, 59))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17))
return this.getData().get('content');
>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
>this : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1))
>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26))
>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16))
}
}
// Repro from #14557
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
>foo : Symbol(foo, Decl(indexedAccessTypeConstraints.ts, 28, 1))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15))
>content : Symbol(content, Decl(indexedAccessTypeConstraints.ts, 32, 27))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42))
>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13))
>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47))
>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15))
x = y;
>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42))
>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47))
}

View File

@@ -0,0 +1,116 @@
=== tests/cases/compiler/indexedAccessTypeConstraints.ts ===
// Repro from #14557
interface IData<T> {
>IData : IData<T>
>T : T
content: T;
>content : T
>T : T
}
type Data<T> = {
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
>T : T
get: <K extends keyof T>(prop: K) => T[K];
>get : <K extends keyof T>(prop: K) => T[K]
>K : K
>T : T
>prop : K
>K : K
>T : T
>K : K
};
class Parent<M> {
>Parent : Parent<M>
>M : M
private data: Data<M>;
>data : { get: <K extends keyof M>(prop: K) => M[K]; }
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
>M : M
getData(): Data<M> {
>getData : () => { get: <K extends keyof M>(prop: K) => M[K]; }
>Data : { get: <K extends keyof T>(prop: K) => T[K]; }
>M : M
return this.data;
>this.data : { get: <K extends keyof M>(prop: K) => M[K]; }
>this : this
>data : { get: <K extends keyof M>(prop: K) => M[K]; }
}
}
export class Foo<C> extends Parent<IData<C>> {
>Foo : Foo<C>
>C : C
>Parent : Parent<IData<C>>
>IData : IData<T>
>C : C
getContent(): C {
>getContent : () => C
>C : C
return this.getData().get('content');
>this.getData().get('content') : C
>this.getData().get : <K extends "content">(prop: K) => IData<C>[K]
>this.getData() : { get: <K extends "content">(prop: K) => IData<C>[K]; }
>this.getData : () => { get: <K extends "content">(prop: K) => IData<C>[K]; }
>this : this
>getData : () => { get: <K extends "content">(prop: K) => IData<C>[K]; }
>get : <K extends "content">(prop: K) => IData<C>[K]
>'content' : "content"
}
}
export class Bar<C, T extends IData<C>> extends Parent<T> {
>Bar : Bar<C, T>
>C : C
>T : T
>IData : IData<T>
>C : C
>Parent : Parent<T>
>T : T
getContent(): C {
>getContent : () => C
>C : C
return this.getData().get('content');
>this.getData().get('content') : T["content"]
>this.getData().get : <K extends keyof T>(prop: K) => T[K]
>this.getData() : { get: <K extends keyof T>(prop: K) => T[K]; }
>this.getData : () => { get: <K extends keyof T>(prop: K) => T[K]; }
>this : this
>getData : () => { get: <K extends keyof T>(prop: K) => T[K]; }
>get : <K extends keyof T>(prop: K) => T[K]
>'content' : "content"
}
}
// Repro from #14557
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
>foo : <C, T extends { content: C; }>(x: C, y: T["content"]) => void
>C : C
>T : T
>content : C
>C : C
>x : C
>C : C
>y : T["content"]
>T : T
x = y;
>x = y : T["content"]
>x : C
>y : T["content"]
}

View File

@@ -0,0 +1,36 @@
// @strict: true
// Repro from #14557
interface IData<T> {
content: T;
}
type Data<T> = {
get: <K extends keyof T>(prop: K) => T[K];
};
class Parent<M> {
private data: Data<M>;
getData(): Data<M> {
return this.data;
}
}
export class Foo<C> extends Parent<IData<C>> {
getContent(): C {
return this.getData().get('content');
}
}
export class Bar<C, T extends IData<C>> extends Parent<T> {
getContent(): C {
return this.getData().get('content');
}
}
// Repro from #14557
function foo<C, T extends { content: C }>(x: C, y: T['content']) {
x = y;
}