TypeScript/tests/cases/compiler/indexedAccessTypeConstraints.ts

37 lines
631 B
TypeScript
Raw Normal View History

2017-03-09 20:57:56 +01:00
// @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> {
2017-11-16 19:58:12 +01:00
constructor(private data: Data<M>) {}
2017-03-09 20:57:56 +01:00
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;
}