mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
b887b30092
**Description:** This is required for https://github.com/swc-project/swc/pull/6981 and https://github.com/swc-project/swc/pull/6950
15 lines
960 B
TypeScript
15 lines
960 B
TypeScript
// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by
|
|
// the type of the property with the numeric name N in the contextual type, if any, or otherwise
|
|
// the numeric index type of the contextual type, if any.
|
|
var array = [1, 2, 3];
|
|
var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type
|
|
var tup: [number, number, number] = [1, 2, 3, 4];
|
|
var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"];
|
|
var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error
|
|
|
|
// In a contextually typed array literal expression containing one or more spread elements,
|
|
// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any.
|
|
var spr = [1, 2, 3, ...array];
|
|
var spr1 = [1, 2, 3, ...tup];
|
|
var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error
|