TypeScript/tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts

46 lines
803 B
TypeScript
Raw Normal View History

2016-12-17 00:01:34 +01:00
// @strictNullChecks: true
// @declaration: true
function f1<T>(x: Partial<T>, y: Readonly<T>) {
let obj: {};
obj = x;
obj = y;
}
function f2<T>(x: Partial<T>, y: Readonly<T>) {
let obj: { [x: string]: any };
obj = x;
obj = y;
}
2017-01-31 01:53:43 +01:00
function f3<T>(x: Partial<T>) {
x = {};
}
2016-12-17 00:01:34 +01:00
// Repro from #12900
interface Base {
2017-01-31 01:53:43 +01:00
foo: { [key: string]: any };
bar: any;
baz: any;
2016-12-17 00:01:34 +01:00
}
interface E1<T> extends Base {
2017-01-31 01:53:43 +01:00
foo: T;
2016-12-17 00:01:34 +01:00
}
interface Something { name: string, value: string };
interface E2 extends Base {
2017-01-31 01:53:43 +01:00
foo: Partial<Something>; // or other mapped type
2016-12-17 00:01:34 +01:00
}
interface E3<T> extends Base {
2017-01-31 01:53:43 +01:00
foo: Partial<T>; // or other mapped type
}
// Repro from #13747
class Form<T> {
private values: {[P in keyof T]?: T[P]} = {}
}