2017-09-15 19:06:58 +02:00
|
|
|
enum E { v1, v2 };
|
|
|
|
|
2016-11-29 09:04:20 +01:00
|
|
|
function f<T extends { b: string }>(p1: T, p2: T[]) {
|
|
|
|
var t: T;
|
|
|
|
|
|
|
|
var i: T["b"];
|
|
|
|
var k: keyof T;
|
|
|
|
|
|
|
|
var mapped_generic: {[P in keyof T]: T[P]};
|
|
|
|
var mapped: {[P in "b"]: T[P]};
|
|
|
|
|
|
|
|
var union_generic: T | { a: number };
|
2017-09-15 19:06:58 +02:00
|
|
|
var union_primitive: { a: number } | number;
|
2016-11-29 09:04:20 +01:00
|
|
|
|
|
|
|
var intersection_generic: T & { a: number };
|
2017-09-15 19:06:58 +02:00
|
|
|
var intersection_primitive: { a: number } | string;
|
|
|
|
|
|
|
|
var num: number;
|
|
|
|
var str: number;
|
|
|
|
var literal_string: "string";
|
|
|
|
var literal_number: 42;
|
2016-11-29 09:04:20 +01:00
|
|
|
|
|
|
|
var u: undefined;
|
|
|
|
var n: null;
|
|
|
|
var a: any;
|
|
|
|
|
2017-09-15 19:06:58 +02:00
|
|
|
|
|
|
|
var e: E;
|
|
|
|
|
2018-10-31 00:33:14 +01:00
|
|
|
var o1 = { ...p1 }; // OK, generic type paramterre
|
|
|
|
var o2 = { ...p2 }; // OK
|
|
|
|
var o3 = { ...t }; // OK, generic type paramter
|
2019-05-01 06:03:03 +02:00
|
|
|
var o4 = { ...i }; // Error, index access
|
2016-11-29 09:04:20 +01:00
|
|
|
var o5 = { ...k }; // Error, index
|
2018-10-31 00:33:14 +01:00
|
|
|
var o6 = { ...mapped_generic }; // OK, generic mapped object type
|
2016-11-29 09:04:20 +01:00
|
|
|
var o7 = { ...mapped }; // OK, non-generic mapped type
|
|
|
|
|
2018-10-31 00:33:14 +01:00
|
|
|
var o8 = { ...union_generic }; // OK, union with generic type parameter
|
2017-09-15 19:06:58 +02:00
|
|
|
var o9 = { ...union_primitive }; // Error, union with generic type parameter
|
2016-11-29 09:04:20 +01:00
|
|
|
|
2018-10-31 00:33:14 +01:00
|
|
|
var o10 = { ...intersection_generic }; // OK, intersection with generic type parameter
|
2017-09-15 19:06:58 +02:00
|
|
|
var o11 = { ...intersection_primitive }; // Error, intersection with generic type parameter
|
|
|
|
|
|
|
|
var o12 = { ...num }; // Error
|
|
|
|
var o13 = { ...str }; // Error
|
2016-11-29 09:04:20 +01:00
|
|
|
|
2017-09-15 19:06:58 +02:00
|
|
|
var o14 = { ...u }; // error, undefined-only not allowed
|
|
|
|
var o15 = { ...n }; // error, null-only not allowed
|
2016-11-29 09:04:20 +01:00
|
|
|
|
|
|
|
var o16 = { ...a }; // OK
|
2017-09-15 19:06:58 +02:00
|
|
|
|
|
|
|
var o17 = { ...literal_string }; // Error
|
|
|
|
var o18 = { ...literal_number }; // Error
|
|
|
|
|
|
|
|
var o19 = { ...e }; // Error, enum
|
2017-09-14 00:13:34 +02:00
|
|
|
}
|