mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Variadic tuple types (#39094)
* Initial implementation of variadic tuple types * Accept new baselines * Handle variadic elements in tuple type inference * Special case inference between tuples with matching structure * Restore check that rest element is last element * Handle variadic tuples in relationship checking * Accept new baselines * Infer readonly constraints when inferring from readonly tuples * Fix lint issues * T assignable to readonly [...T] and [...T] assignable to T * Consistent tuple normalization * Create variadic tuple types from array literal expressions * Accept new baselines * Array literals have tuple types when contextual type is readonly * Accept new baselines * Optional elements before required elements become required elements * Update logic for rest parameters and spread arguments * Revert special case of contextual readonly array type * Accept new baselines * Fix lint issue * Switch entirely to createTupleType based on element flags * Don't infer readonly tuple types when inferring to variadic elements * Handle mapped types applied to generic tuple types * Handle constraint of indexed access type with generic tuple type * Accept new baselines * Address CR feedback * Simplify indexed access types involving generic tuple types * Propagate checkMode into getSpreadArgumentType * Guard against missing globalArrayType * Inference to [...T, ...U] based on implied arity of T * Accept new baselines * Add tests * Emit .d.ts from tests * Address CR feedback
This commit is contained in:
1 parent
e6aedfd38b
commit
d4792062bf
83 files changed
+4282
-702
No files matched your search
+601
-311
File diff suppressed because it is too large.
Load diff
@@ -1201,6 +1201,14 @@ namespace ts {
|
||||
return values;
|
||||
}
|
||||
|
||||
export function arrayOf<T>(count: number, f: (index: number) => T): T[] {
|
||||
const result = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = f(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Shims `Array.from`. */
|
||||
export function arrayFrom<T, U>(iterator: Iterator<T> | IterableIterator<T>, map: (t: T) => U): U[];
|
||||
export function arrayFrom<T>(iterator: Iterator<T> | IterableIterator<T>): T[];
|
||||
|
||||
@@ -2414,6 +2414,26 @@
|
||||
"category": "Error",
|
||||
"code": 2617
|
||||
},
|
||||
"Source has {0} element(s) but target requires {1}.": {
|
||||
"category": "Error",
|
||||
"code": 2618
|
||||
},
|
||||
"Source has {0} element(s) but target allows only {1}.": {
|
||||
"category": "Error",
|
||||
"code": 2619
|
||||
},
|
||||
"Target requires {0} element(s) but source may have fewer.": {
|
||||
"category": "Error",
|
||||
"code": 2620
|
||||
},
|
||||
"Target allows only {0} element(s) but source may have more.": {
|
||||
"category": "Error",
|
||||
"code": 2621
|
||||
},
|
||||
"Element at index {0} is variadic in one type but not in the other.": {
|
||||
"category": "Error",
|
||||
"code": 2622
|
||||
},
|
||||
|
||||
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
|
||||
"category": "Error",
|
||||
|
||||
@@ -5100,9 +5100,20 @@ namespace ts {
|
||||
variances?: VarianceFlags[]; // Variance of each type parameter
|
||||
}
|
||||
|
||||
export const enum ElementFlags {
|
||||
Required = 1 << 0, // T
|
||||
Optional = 1 << 1, // T?
|
||||
Rest = 1 << 2, // ...T[]
|
||||
Variadic = 1 << 3, // ...T
|
||||
Variable = Rest | Variadic,
|
||||
}
|
||||
|
||||
export interface TupleType extends GenericType {
|
||||
elementFlags: readonly ElementFlags[];
|
||||
minLength: number;
|
||||
fixedLength: number;
|
||||
hasRestElement: boolean;
|
||||
combinedFlags: ElementFlags;
|
||||
readonly: boolean;
|
||||
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
|
||||
}
|
||||
@@ -5422,6 +5433,7 @@ namespace ts {
|
||||
priority?: InferencePriority; // Priority of current inference set
|
||||
topLevel: boolean; // True if all inferences are to top level occurrences
|
||||
isFixed: boolean; // True if inferences are fixed
|
||||
impliedArity?: number;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@@ -2538,9 +2538,19 @@ declare namespace ts {
|
||||
}
|
||||
export interface GenericType extends InterfaceType, TypeReference {
|
||||
}
|
||||
export enum ElementFlags {
|
||||
Required = 1,
|
||||
Optional = 2,
|
||||
Rest = 4,
|
||||
Variadic = 8,
|
||||
Variable = 12
|
||||
}
|
||||
export interface TupleType extends GenericType {
|
||||
elementFlags: readonly ElementFlags[];
|
||||
minLength: number;
|
||||
fixedLength: number;
|
||||
hasRestElement: boolean;
|
||||
combinedFlags: ElementFlags;
|
||||
readonly: boolean;
|
||||
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
|
||||
}
|
||||
|
||||
+10
@@ -2538,9 +2538,19 @@ declare namespace ts {
|
||||
}
|
||||
export interface GenericType extends InterfaceType, TypeReference {
|
||||
}
|
||||
export enum ElementFlags {
|
||||
Required = 1,
|
||||
Optional = 2,
|
||||
Rest = 4,
|
||||
Variadic = 8,
|
||||
Variable = 12
|
||||
}
|
||||
export interface TupleType extends GenericType {
|
||||
elementFlags: readonly ElementFlags[];
|
||||
minLength: number;
|
||||
fixedLength: number;
|
||||
hasRestElement: boolean;
|
||||
combinedFlags: ElementFlags;
|
||||
readonly: boolean;
|
||||
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(16,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
|
||||
Type '(string | number | boolean)[]' is missing the following properties from type '[string, number, boolean]': 0, 1, 2
|
||||
Target requires 3 element(s) but source may have fewer.
|
||||
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(17,5): error TS2345: Argument of type '[string, number, true, ...(string | number | boolean)[]]' is not assignable to parameter of type '[string, number, boolean]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type 'number' is not assignable to type '3'.
|
||||
Target allows only 3 element(s) but source may have more.
|
||||
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(18,5): error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'.
|
||||
Types of property 'x' are incompatible.
|
||||
Type '(string | number)[]' is missing the following properties from type '[any, any]': 0, 1
|
||||
Type '(string | number)[]' is not assignable to type '[any, any]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (3 errors) ====
|
||||
@@ -27,14 +27,14 @@ tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextua
|
||||
baz(array); // Error
|
||||
~~~~~
|
||||
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
|
||||
!!! error TS2345: Type '(string | number | boolean)[]' is missing the following properties from type '[string, number, boolean]': 0, 1, 2
|
||||
!!! error TS2345: Target requires 3 element(s) but source may have fewer.
|
||||
baz(["string", 1, true, ...array]); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[string, number, true, ...(string | number | boolean)[]]' is not assignable to parameter of type '[string, number, boolean]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type 'number' is not assignable to type '3'.
|
||||
!!! error TS2345: Target allows only 3 element(s) but source may have more.
|
||||
foo(o); // Error because x has an array type namely (string|number)[]
|
||||
~
|
||||
!!! error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'.
|
||||
!!! error TS2345: Types of property 'x' are incompatible.
|
||||
!!! error TS2345: Type '(string | number)[]' is missing the following properties from type '[any, any]': 0, 1
|
||||
!!! error TS2345: Type '(string | number)[]' is not assignable to type '[any, any]'.
|
||||
!!! error TS2345: Target requires 2 element(s) but source may have fewer.
|
||||
@@ -1,21 +1,21 @@
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): error TS2493: Tuple type '[string, number]' of length '2' has no element at index '2'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2461: Type '{ 0: string; 1: number; length: 2; }' is not an array type.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2741: Property '2' is missing in type '[string, number]' but required in type '[number, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2741: Property '2' is missing in type 'StrNum' but required in type '[number, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2741: Property '2' is missing in type '[string, number]' but required in type '[string, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2741: Property '2' is missing in type 'StrNum' but required in type '[string, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string, number, number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
Source has 2 element(s) but target allows only 1.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '2' is not assignable to type '1'.
|
||||
Source has 2 element(s) but target allows only 1.
|
||||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '2' is not assignable to type '1'.
|
||||
@@ -52,7 +52,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
|
||||
!!! error TS2461: Type '{ 0: string; 1: number; length: 2; }' is not an array type.
|
||||
var j1: [number, number, number] = x;
|
||||
~~
|
||||
!!! error TS2741: Property '2' is missing in type '[string, number]' but required in type '[number, number, number]'.
|
||||
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Source has 2 element(s) but target requires 3.
|
||||
var j2: [number, number, number] = y;
|
||||
~~
|
||||
!!! error TS2741: Property '2' is missing in type 'StrNum' but required in type '[number, number, number]'.
|
||||
@@ -61,7 +62,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
|
||||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'.
|
||||
var k1: [string, number, number] = x;
|
||||
~~
|
||||
!!! error TS2741: Property '2' is missing in type '[string, number]' but required in type '[string, number, number]'.
|
||||
!!! error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'.
|
||||
!!! error TS2322: Source has 2 element(s) but target requires 3.
|
||||
var k2: [string, number, number] = y;
|
||||
~~
|
||||
!!! error TS2741: Property '2' is missing in type 'StrNum' but required in type '[string, number, number]'.
|
||||
@@ -71,8 +73,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
|
||||
var l1: [number] = x;
|
||||
~~
|
||||
!!! error TS2322: Type '[string, number]' is not assignable to type '[number]'.
|
||||
!!! error TS2322: Types of property '0' are incompatible.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
!!! error TS2322: Source has 2 element(s) but target allows only 1.
|
||||
var l2: [number] = y;
|
||||
~~
|
||||
!!! error TS2322: Type 'StrNum' is not assignable to type '[number]'.
|
||||
@@ -84,8 +85,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
|
||||
var m1: [string] = x;
|
||||
~~
|
||||
!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '2' is not assignable to type '1'.
|
||||
!!! error TS2322: Source has 2 element(s) but target allows only 1.
|
||||
var m2: [string] = y;
|
||||
~~
|
||||
!!! error TS2322: Type 'StrNum' is not assignable to type '[string]'.
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(6,5): error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(7,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[string | number, string | number, string | number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type '[number, number, number, number, number, number]' is not assignable to type '[number, number, number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '6' is not assignable to type '3'.
|
||||
Source has 6 element(s) but target allows only 3.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (4 errors) ====
|
||||
@@ -21,18 +17,15 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte
|
||||
var tup: [number, number, number] = [1, 2, 3, 4];
|
||||
~~~
|
||||
!!! error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2322: Source has 4 element(s) but target allows only 3.
|
||||
var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"];
|
||||
~~~~
|
||||
!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[string | number, string | number, string | number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2322: Source has 4 element(s) but target allows only 3.
|
||||
var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error
|
||||
~~~~
|
||||
!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2322: Source has 4 element(s) but target allows only 3.
|
||||
|
||||
// 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.
|
||||
@@ -41,6 +34,5 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte
|
||||
var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error
|
||||
~~~~
|
||||
!!! error TS2322: Type '[number, number, number, number, number, number]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '6' is not assignable to type '3'.
|
||||
!!! error TS2322: Source has 6 element(s) but target allows only 3.
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2739: Type '[]' is missing the following properties from type '[any, any, any]': 0, 1, 2
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2322: Type '[]' is not assignable to type '[any, any, any]'.
|
||||
Source has 0 element(s) but target requires 3.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,38): error TS2322: Type 'string' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,48): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,51): error TS2322: Type 'boolean' is not assignable to type 'number'.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '2'.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2739: Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2
|
||||
Source has 4 element(s) but target allows only 2.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
|
||||
Target requires 3 element(s) but source may have fewer.
|
||||
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
|
||||
The types returned by 'pop()' are incompatible between these types.
|
||||
Type 'string | number' is not assignable to type 'Number'.
|
||||
@@ -24,7 +25,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
|
||||
|
||||
var a0: [any, any, any] = []; // Error
|
||||
~~
|
||||
!!! error TS2739: Type '[]' is missing the following properties from type '[any, any, any]': 0, 1, 2
|
||||
!!! error TS2322: Type '[]' is not assignable to type '[any, any, any]'.
|
||||
!!! error TS2322: Source has 0 element(s) but target requires 3.
|
||||
var a1: [boolean, string, number] = ["string", 1, true]; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
|
||||
@@ -40,8 +42,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
|
||||
var [b1, b2]: [number, number] = [1, 2, "string", true];
|
||||
~~~~~~~~
|
||||
!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '4' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 4 element(s) but target allows only 2.
|
||||
|
||||
// The resulting type an array literal expression is determined as follows:
|
||||
// - the resulting type is an array type with an element type that is the union of the types of the
|
||||
@@ -59,7 +60,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
|
||||
var c0: tup = [...temp2]; // Error
|
||||
var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number]
|
||||
~~
|
||||
!!! error TS2739: Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
|
||||
!!! error TS2322: Target requires 3 element(s) but source may have fewer.
|
||||
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
|
||||
~~
|
||||
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2741: Property '0' is missing in type '{}[]' but required in type '[{}]'.
|
||||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ====
|
||||
@@ -28,5 +29,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
emptyObjTuple = emptyObjArray;
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2741: Property '0' is missing in type '{}[]' but required in type '[{}]'.
|
||||
!!! error TS2322: Type '{}[]' is not assignable to type '[{}]'.
|
||||
!!! error TS2322: Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
@@ -225,8 +225,8 @@ foo() = value;
|
||||
|
||||
([]) = value;
|
||||
>([]) = value : any
|
||||
>([]) : undefined[]
|
||||
>[] : undefined[]
|
||||
>([]) : []
|
||||
>[] : []
|
||||
>value : any
|
||||
|
||||
(function baz() { }) = value;
|
||||
|
||||
@@ -4,7 +4,7 @@ var tuple: [string, number];
|
||||
|
||||
[...c] = tupel; // intentionally misspelled
|
||||
>[...c] = tupel : any
|
||||
>[...c] : undefined[]
|
||||
>[...c] : any[]
|
||||
>...c : any
|
||||
>c : any
|
||||
>tupel : any
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(14,10): error TS2554: Expected 2 arguments, but got 3.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(15,15): error TS2554: Expected 2 arguments, but got 5.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(16,15): error TS2556: Expected 2 arguments, but got 4 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(17,15): error TS2556: Expected 2 arguments, but got 5 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(18,12): error TS2556: Expected 2 arguments, but got 1 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(16,15): error TS2554: Expected 2 arguments, but got 5.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(17,15): error TS2554: Expected 2 arguments, but got 6.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(18,12): error TS2554: Expected 2 arguments, but got 3.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(19,5): error TS2554: Expected 2 arguments, but got 3.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(20,6): error TS2557: Expected at least 2 arguments, but got 0 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(21,6): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(22,13): error TS2557: Expected at least 2 arguments, but got 1 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(23,13): error TS2557: Expected at least 2 arguments, but got 2 or more.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(25,7): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
||||
tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(31,13): error TS2557: Expected at least 2 arguments, but got 4 or more.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts (11 errors) ====
|
||||
==== tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts (12 errors) ====
|
||||
declare const s2: [string, string];
|
||||
declare const s3: [string, string, string];
|
||||
declare const s2_: [string, string, ...string[]];
|
||||
@@ -33,14 +34,13 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(25,7): erro
|
||||
!!! error TS2554: Expected 2 arguments, but got 5.
|
||||
fs2('a', 'b', ...s2, 'c'); // error on ...s2 and 'c'
|
||||
~~~~~~~~~~
|
||||
!!! error TS2556: Expected 2 arguments, but got 4 or more.
|
||||
!!! error TS2554: Expected 2 arguments, but got 5.
|
||||
fs2('a', 'b', 'c', ...s2, 'd'); // error on 'c', ...s2 and 'd'
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2556: Expected 2 arguments, but got 5 or more.
|
||||
!!! error TS2554: Expected 2 arguments, but got 6.
|
||||
fs2(...s2, 'a'); // error on 'a'
|
||||
~~~
|
||||
!!! error TS2556: Expected 2 arguments, but got 1 or more.
|
||||
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts:8:33: An argument for 'b' was not provided.
|
||||
!!! error TS2554: Expected 2 arguments, but got 3.
|
||||
fs2(...s3); // error on ...s3
|
||||
~~~~~
|
||||
!!! error TS2554: Expected 2 arguments, but got 3.
|
||||
@@ -68,6 +68,8 @@ tests/cases/conformance/expressions/functionCalls/callWithSpread3.ts(25,7): erro
|
||||
fs2_(...s2_, ...s_);
|
||||
fs2_(...s2_, ...s2_);
|
||||
fs2_(...s_, ...s2_);
|
||||
~~~~~~
|
||||
!!! error TS2557: Expected at least 2 arguments, but got 4 or more.
|
||||
fs2n_(...s2n_);
|
||||
fs2n_(...s2);
|
||||
// fs2n_(...s2, ...n_); // FIXME: should compile
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2352: Conversion of type '[number, string]' to type '[number, string, boolean]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
Property '2' is missing in type '[number, string]' but required in type '[number, string, boolean]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(14,15): error TS2352: Conversion of type '[number, string, boolean]' to type '[number, string]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not comparable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(15,14): error TS2352: Conversion of type '[number, string]' to type '[number, string, boolean]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(18,21): error TS2352: Conversion of type '[C, D]' to type '[C, D, A]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
Property '2' is missing in type '[C, D]' but required in type '[C, D, A]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(20,33): error TS2493: Tuple type '[C, D, A]' of length '3' has no element at index '5'.
|
||||
tests/cases/conformance/types/tuple/castingTuple.ts(30,10): error TS2352: Conversion of type '[number, string]' to type '[number, number]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
Type 'string' is not comparable to type 'number'.
|
||||
@@ -31,12 +30,11 @@ tests/cases/conformance/types/tuple/castingTuple.ts(33,1): error TS2304: Cannot
|
||||
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Conversion of type '[number, string]' to type '[number, string, boolean]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
!!! error TS2352: Property '2' is missing in type '[number, string]' but required in type '[number, string, boolean]'.
|
||||
!!! error TS2352: Source has 2 element(s) but target requires 3.
|
||||
var shorter = numStrBoolTuple as [number, string]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Conversion of type '[number, string, boolean]' to type '[number, string]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
!!! error TS2352: Types of property 'length' are incompatible.
|
||||
!!! error TS2352: Type '3' is not comparable to type '2'.
|
||||
!!! error TS2352: Source has 3 element(s) but target allows only 2.
|
||||
var longer = numStrTuple as [number, string, boolean]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Conversion of type '[number, string]' to type '[number, string, boolean]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
@@ -45,7 +43,7 @@ tests/cases/conformance/types/tuple/castingTuple.ts(33,1): error TS2304: Cannot
|
||||
var classCDATuple = <[C, D, A]>classCDTuple;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Conversion of type '[C, D]' to type '[C, D, A]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||
!!! error TS2352: Property '2' is missing in type '[C, D]' but required in type '[C, D, A]'.
|
||||
!!! error TS2352: Source has 2 element(s) but target requires 3.
|
||||
var eleFromCDA1 = classCDATuple[2]; // A
|
||||
var eleFromCDA2 = classCDATuple[5]; // C | D | A
|
||||
~
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,18): error TS2769: No overload matches this call.
|
||||
Overload 1 of 2, '(props: Readonly<ResizablePanelProps>): ResizablePanel', gave the following error.
|
||||
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
|
||||
The types of 'children.length' are incompatible between these types.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
Overload 2 of 2, '(props: ResizablePanelProps, context?: any): ResizablePanel', gave the following error.
|
||||
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
|
||||
Types of property 'children' are incompatible.
|
||||
@@ -31,8 +32,9 @@ tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,18): error TS2
|
||||
!!! error TS2769: No overload matches this call.
|
||||
!!! error TS2769: Overload 1 of 2, '(props: Readonly<ResizablePanelProps>): ResizablePanel', gave the following error.
|
||||
!!! error TS2769: Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
|
||||
!!! error TS2769: The types of 'children.length' are incompatible between these types.
|
||||
!!! error TS2769: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2769: Types of property 'children' are incompatible.
|
||||
!!! error TS2769: Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
|
||||
!!! error TS2769: Source has 3 element(s) but target allows only 2.
|
||||
!!! error TS2769: Overload 2 of 2, '(props: ResizablePanelProps, context?: any): ResizablePanel', gave the following error.
|
||||
!!! error TS2769: Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
|
||||
!!! error TS2769: Types of property 'children' are incompatible.
|
||||
|
||||
@@ -432,14 +432,14 @@ foo() += value;
|
||||
|
||||
([]) *= value;
|
||||
>([]) *= value : number
|
||||
>([]) : undefined[]
|
||||
>[] : undefined[]
|
||||
>([]) : []
|
||||
>[] : []
|
||||
>value : any
|
||||
|
||||
([]) += value;
|
||||
>([]) += value : any
|
||||
>([]) : undefined[]
|
||||
>[] : undefined[]
|
||||
>([]) : []
|
||||
>[] : []
|
||||
>value : any
|
||||
|
||||
(function baz1() { }) *= value;
|
||||
|
||||
@@ -244,8 +244,8 @@ foo() **= value;
|
||||
|
||||
([]) **= value;
|
||||
>([]) **= value : number
|
||||
>([]) : undefined[]
|
||||
>[] : undefined[]
|
||||
>([]) : []
|
||||
>[] : []
|
||||
>value : any
|
||||
|
||||
(function baz1() { }) **= value;
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,17): error TS2741: Property 'a' is missing in type '{}' but required in type '{ a: string; }'.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(19,1): error TS2741: Property '2' is missing in type '[number, string]' but required in type '[number, string, boolean]'.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(19,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(20,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(23,1): error TS2322: Type '[C, string | number, D]' is not assignable to type '[C, string | number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(24,1): error TS2741: Property '2' is missing in type '[C, string | number]' but required in type '[C, string | number, D]'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(24,1): error TS2322: Type '[C, string | number]' is not assignable to type '[C, string | number, D]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS2322: Type '[number, string | number]' is not assignable to type '[number, string]'.
|
||||
Type 'string | number' is not assignable to type 'string'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
@@ -24,8 +22,7 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
|
||||
var numStrTuple2: [number, string] = [5, "foo", true];
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
|
||||
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
|
||||
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
|
||||
@@ -40,8 +37,7 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
|
||||
numStrTuple = numStrBoolTuple;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
|
||||
// error
|
||||
objNumTuple = [ {}, 5];
|
||||
@@ -50,22 +46,22 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
|
||||
!!! related TS2728 tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts:5:21: 'a' is declared here.
|
||||
numStrBoolTuple = numStrTuple;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2741: Property '2' is missing in type '[number, string]' but required in type '[number, string, boolean]'.
|
||||
!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]'.
|
||||
!!! error TS2322: Source has 2 element(s) but target requires 3.
|
||||
var strStrTuple: [string, string] = ["foo", "bar", 5];
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
|
||||
unionTuple = unionTuple1;
|
||||
unionTuple = unionTuple2;
|
||||
~~~~~~~~~~
|
||||
!!! error TS2322: Type '[C, string | number, D]' is not assignable to type '[C, string | number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
unionTuple2 = unionTuple;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2741: Property '2' is missing in type '[C, string | number]' but required in type '[C, string | number, D]'.
|
||||
!!! error TS2322: Type '[C, string | number]' is not assignable to type '[C, string | number, D]'.
|
||||
!!! error TS2322: Source has 2 element(s) but target requires 3.
|
||||
numStrTuple = unionTuple3;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type '[number, string | number]' is not assignable to type '[number, string]'.
|
||||
|
||||
@@ -4,8 +4,10 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2493: Tuple type '[]' of length '0' has no element at index '1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type.
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,51): error TS2322: Type 'number' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(22,5): error TS2739: Type 'number[]' is missing the following properties from type '[number, number]': 0, 1
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(23,5): error TS2739: Type 'number[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(22,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(23,5): error TS2322: Type 'number[]' is not assignable to type '[string, string]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type.
|
||||
|
||||
|
||||
@@ -45,10 +47,12 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss
|
||||
var temp = [1, 2, 3]
|
||||
var [c0, c1]: [number, number] = [...temp]; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS2739: Type 'number[]' is missing the following properties from type '[number, number]': 0, 1
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[number, number]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
var [c2, c3]: [string, string] = [...temp]; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS2739: Type 'number[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[string, string]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
|
||||
interface F {
|
||||
[idx: number]: boolean
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(12,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(57,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(62,10): error TS2393: Duplicate function implementation.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(63,10): error TS2393: Duplicate function implementation.
|
||||
|
||||
@@ -23,8 +21,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.
|
||||
a1([1, 2, [["world"]], 3]);
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 4 element(s) but target allows only 3.
|
||||
|
||||
// If the declaration includes an initializer expression (which is permitted only
|
||||
// when the parameter list occurs in conjunction with a function body),
|
||||
@@ -72,8 +69,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.
|
||||
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
|
||||
// or by including an initializer.
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(12,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(57,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(62,10): error TS2393: Duplicate function implementation.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(63,10): error TS2393: Duplicate function implementation.
|
||||
|
||||
@@ -23,8 +21,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5i
|
||||
a1([1, 2, [["world"]], 3]);
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 4 element(s) but target allows only 3.
|
||||
|
||||
// If the declaration includes an initializer expression (which is permitted only
|
||||
// when the parameter list occurs in conjunction with a function body),
|
||||
@@ -72,8 +69,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5i
|
||||
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
|
||||
// or by including an initializer.
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(14,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(58,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,18): error TS2300: Duplicate identifier 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,26): error TS2300: Duplicate identifier 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,34): error TS2300: Duplicate identifier 'number'.
|
||||
@@ -26,8 +24,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.
|
||||
a1([1, 2, [["world"]], 3]);
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 4 element(s) but target allows only 3.
|
||||
|
||||
|
||||
// If the declaration includes an initializer expression (which is permitted only
|
||||
@@ -74,8 +71,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.
|
||||
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
|
||||
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,8): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,29): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '3'.
|
||||
Source has 4 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,16): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
@@ -43,8 +42,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
|
||||
a0([1, 2, [["world"]], "string"]); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '4' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 4 element(s) but target allows only 3.
|
||||
|
||||
|
||||
// If the declaration includes an initializer expression (which is permitted only
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(29,12): error TS2322: Type 'number' is not assignable to type '[[any]]'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts (3 errors) ====
|
||||
@@ -35,8 +34,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.
|
||||
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
|
||||
a10([1, 2, 3, false, true]); // Parameter type is any[]
|
||||
@@ -45,7 +43,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.
|
||||
a10([1, 2]); // Parameter type is any[]
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Source has 2 element(s) but target requires 3.
|
||||
a11([1, 2]); // Parameter type is number[]
|
||||
|
||||
// Rest parameter with generic
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(29,12): error TS2322: Type 'number' is not assignable to type '[[any]]'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts (3 errors) ====
|
||||
@@ -35,8 +34,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5i
|
||||
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
|
||||
a10([1, 2, 3, false, true]); // Parameter type is any[]
|
||||
@@ -45,7 +43,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5i
|
||||
a10([1, 2]); // Parameter type is any[]
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Source has 2 element(s) but target requires 3.
|
||||
a11([1, 2]); // Parameter type is number[]
|
||||
|
||||
// Rest parameter with generic
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '5' is not assignable to type '3'.
|
||||
Source has 5 element(s) but target allows only 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(29,12): error TS2322: Type 'number' is not assignable to type '[[any]]'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(30,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts (3 errors) ====
|
||||
@@ -35,8 +34,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.
|
||||
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '5' is not assignable to type '3'.
|
||||
!!! error TS2345: Source has 5 element(s) but target allows only 3.
|
||||
|
||||
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
|
||||
a10([1, 2, 3, false, true]); // Parameter type is any[]
|
||||
@@ -45,7 +43,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.
|
||||
a10([1, 2]); // Parameter type is any[]
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]], ...any[]]'.
|
||||
!!! error TS2345: Source has 2 element(s) but target requires 3.
|
||||
a11([1, 2]); // Parameter type is number[]
|
||||
|
||||
// Rest parameter with generic
|
||||
|
||||
@@ -4,7 +4,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,11): error TS2322: Type 'string' is not assignable to type '[[any]]'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(23,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]]]'.
|
||||
Source has 2 element(s) but target requires 3.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,11): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,17): error TS1317: A parameter property cannot be declared using a rest parameter.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'.
|
||||
@@ -48,7 +48,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
|
||||
a5([1, 2]); // Error, parameter type is [any, any, [[any]]]
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Property '2' is missing in type '[number, number]' but required in type '[any, any, [[any]]]'.
|
||||
!!! error TS2345: Source has 2 element(s) but target requires 3.
|
||||
a6([1, 2, "string"]); // Error, parameter type is number[]
|
||||
~~~~~~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
@@ -4,8 +4,7 @@ tests/cases/compiler/destructuringTuple.ts(11,48): error TS2769: No overload mat
|
||||
Type 'never[]' is not assignable to type 'number'.
|
||||
Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
|
||||
Type 'never[]' is not assignable to type '[]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type 'number' is not assignable to type '0'.
|
||||
Target allows only 0 element(s) but source may have more.
|
||||
tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload matches this call.
|
||||
Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
|
||||
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
|
||||
@@ -33,8 +32,7 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
|
||||
!!! error TS2769: Type 'never[]' is not assignable to type 'number'.
|
||||
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
|
||||
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
|
||||
!!! error TS2769: Types of property 'length' are incompatible.
|
||||
!!! error TS2769: Type 'number' is not assignable to type '0'.
|
||||
!!! error TS2769: Target allows only 0 element(s) but source may have more.
|
||||
!!! related TS6502 /.ts/lib.es5.d.ts:1368:24: The expected type comes from the return type of this signature.
|
||||
!!! related TS6502 /.ts/lib.es5.d.ts:1374:27: The expected type comes from the return type of this signature.
|
||||
~~
|
||||
|
||||
@@ -170,7 +170,7 @@ for (obj?.a["b"] of []);
|
||||
|
||||
[...obj?.["a"]] = [];
|
||||
>[...obj?.["a"]] = [] : never[]
|
||||
>[...obj?.["a"]] : never[]
|
||||
>[...obj?.["a"]] : any[]
|
||||
>...obj?.["a"] : any
|
||||
>obj?.["a"] : any
|
||||
>obj : any
|
||||
@@ -179,7 +179,7 @@ for (obj?.a["b"] of []);
|
||||
|
||||
[...obj?.a["b"]] = [];
|
||||
>[...obj?.a["b"]] = [] : never[]
|
||||
>[...obj?.a["b"]] : never[]
|
||||
>[...obj?.a["b"]] : any[]
|
||||
>...obj?.a["b"] : any
|
||||
>obj?.a["b"] : any
|
||||
>obj?.a : any
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
var a = [] = [1].map(_ => _);
|
||||
>a : number[]
|
||||
>[] = [1].map(_ => _) : number[]
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[1].map(_ => _) : number[]
|
||||
>[1].map : <U>(callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[]
|
||||
>[1] : number[]
|
||||
|
||||
@@ -11,7 +11,7 @@ var a: any;
|
||||
([] = a);
|
||||
>([] = a) : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
var [,] = [1,2];
|
||||
|
||||
@@ -11,6 +11,6 @@ var a: any;
|
||||
([] = a);
|
||||
>([] = a) : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -11,6 +11,6 @@ var a: any;
|
||||
([] = a);
|
||||
>([] = a) : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -24,7 +24,7 @@ let x, y, z, a1, a2, a3;
|
||||
([] = [ a1, a2, a3] = a);
|
||||
>([] = [ a1, a2, a3] = a) : any
|
||||
>[] = [ a1, a2, a3] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[ a1, a2, a3] = a : any
|
||||
>[ a1, a2, a3] : [any, any, any]
|
||||
>a1 : any
|
||||
|
||||
@@ -24,7 +24,7 @@ let x, y, z, a1, a2, a3;
|
||||
([] = [ a1, a2, a3] = a);
|
||||
>([] = [ a1, a2, a3] = a) : any
|
||||
>[] = [ a1, a2, a3] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[ a1, a2, a3] = a : any
|
||||
>[ a1, a2, a3] : [any, any, any]
|
||||
>a1 : any
|
||||
|
||||
@@ -24,7 +24,7 @@ let x, y, z, a1, a2, a3;
|
||||
([] = [ a1, a2, a3] = a);
|
||||
>([] = [ a1, a2, a3] = a) : any
|
||||
>[] = [ a1, a2, a3] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[ a1, a2, a3] = a : any
|
||||
>[ a1, a2, a3] : [any, any, any]
|
||||
>a1 : any
|
||||
|
||||
@@ -13,8 +13,8 @@ var a: any;
|
||||
([] = [] = a);
|
||||
>([] = [] = a) : any
|
||||
>[] = [] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -13,8 +13,8 @@ var a: any;
|
||||
([] = [] = a);
|
||||
>([] = [] = a) : any
|
||||
>[] = [] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -13,8 +13,8 @@ var a: any;
|
||||
([] = [] = a);
|
||||
>([] = [] = a) : any
|
||||
>[] = [] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -29,6 +29,6 @@ let x, y, z, a1, a2, a3;
|
||||
>a2 : any
|
||||
>a3 : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -29,6 +29,6 @@ let x, y, z, a1, a2, a3;
|
||||
>a2 : any
|
||||
>a3 : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -29,6 +29,6 @@ let x, y, z, a1, a2, a3;
|
||||
>a2 : any
|
||||
>a3 : any
|
||||
>[] = a : any
|
||||
>[] : undefined[]
|
||||
>[] : []
|
||||
>a : any
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(12,1): error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '4' is not assignable to type '2'.
|
||||
Source has 4 element(s) but target allows only 2.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(13,20): error TS2493: Tuple type '[string, number]' of length '2' has no element at index '2'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'undefined'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,11): error TS2493: Tuple type '[string, number]' of length '2' has no element at index '3'.
|
||||
@@ -9,7 +8,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,17): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,14): error TS2322: Type '{}' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,18): error TS2322: Type '{}' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2741: Property '1' is missing in type '[{}]' but required in type '[{}, {}]'.
|
||||
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts (10 errors) ====
|
||||
@@ -27,8 +27,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
|
||||
i1.tuple1 = ["foo", 5, false, true];
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '4' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 4 element(s) but target allows only 2.
|
||||
var e3 = i1.tuple1[2]; // {}
|
||||
~
|
||||
!!! error TS2493: Tuple type '[string, number]' of length '2' has no element at index '2'.
|
||||
@@ -58,5 +57,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'number'.
|
||||
i2.tuple1 = [{}];
|
||||
~~~~~~~~~
|
||||
!!! error TS2741: Property '1' is missing in type '[{}]' but required in type '[{}, {}]'.
|
||||
!!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'.
|
||||
!!! error TS2322: Source has 1 element(s) but target requires 2.
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
tests/cases/conformance/types/rest/genericRestParameters1.ts(22,4): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters1.ts(31,4): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
|
||||
Type 'Function' provides no match for the signature '(...args: any): any'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not assignable to type '(...args: any[]) => void'.
|
||||
@@ -9,7 +5,7 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232
|
||||
Type 'any' is not assignable to type 'never'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/genericRestParameters1.ts (4 errors) ====
|
||||
==== tests/cases/conformance/types/rest/genericRestParameters1.ts (2 errors) ====
|
||||
declare let f1: (...x: [number, string, boolean]) => void;
|
||||
declare let f2: (x0: number, x1: string, x2: boolean) => void;
|
||||
|
||||
@@ -32,9 +28,6 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232
|
||||
f1(42, "hello", true, ...t0);
|
||||
f1(ns[0], ns[1], true);
|
||||
f1(...ns, true); // FIXME: Error, since ...ns is considered as string|number here
|
||||
~~~~~
|
||||
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
f2(42, "hello", true);
|
||||
f2(t3[0], t3[1], t3[2]);
|
||||
@@ -44,9 +37,6 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232
|
||||
f2(42, "hello", true, ...t0);
|
||||
f2(ns[0], ns[1], true);
|
||||
f2(...ns, true); // FIXME: Error, since ...ns is considered as string|number here
|
||||
~~~~~
|
||||
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
declare function f10<T extends unknown[]>(...args: T): T;
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ declare const x14: [number, string, boolean];
|
||||
declare const x15: [number, string, boolean];
|
||||
declare const x16: [number, string, boolean];
|
||||
declare const x17: [number, string, boolean];
|
||||
declare const x18: (string | number | boolean)[];
|
||||
declare const x18: [number, string, boolean];
|
||||
declare function g10<U extends string[], V extends [number, number]>(u: U, v: V): void;
|
||||
declare function f11<T extends (string | number | boolean)[]>(...args: T): T;
|
||||
declare const z10: [42, "hello", true];
|
||||
@@ -307,7 +307,7 @@ declare const z14: [number, string, boolean];
|
||||
declare const z15: [42, string, boolean];
|
||||
declare const z16: [42, "hello", boolean];
|
||||
declare const z17: [42, "hello", true];
|
||||
declare const z18: (string | number | true)[];
|
||||
declare const z18: [number, string, true];
|
||||
declare function g11<U extends string[], V extends [number, number]>(u: U, v: V): void;
|
||||
declare function call<T extends unknown[], U>(f: (...args: T) => U, ...args: T): U;
|
||||
declare function callr<T extends unknown[], U>(args: T, f: (...args: T) => U): U;
|
||||
|
||||
@@ -238,8 +238,8 @@ const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean]
|
||||
>t0 : []
|
||||
|
||||
const x18 = f10(...ns, true); // (string | number | boolean)[]
|
||||
>x18 : (string | number | boolean)[]
|
||||
>f10(...ns, true) : (string | number | boolean)[]
|
||||
>x18 : [number, string, boolean]
|
||||
>f10(...ns, true) : [number, string, boolean]
|
||||
>f10 : <T extends unknown[]>(...args: T) => T
|
||||
>...ns : string | number
|
||||
>ns : [number, string]
|
||||
@@ -265,16 +265,16 @@ function g10<U extends string[], V extends [number, number]>(u: U, v: V) {
|
||||
>v : V
|
||||
|
||||
let x3 = f10(1, ...u); // [number, ...string[]]
|
||||
>x3 : [number, ...string[]]
|
||||
>f10(1, ...u) : [number, ...string[]]
|
||||
>x3 : [number, ...U]
|
||||
>f10(1, ...u) : [number, ...U]
|
||||
>f10 : <T extends unknown[]>(...args: T) => T
|
||||
>1 : 1
|
||||
>...u : string
|
||||
>u : U
|
||||
|
||||
let x4 = f10(...u, ...v); // (string | number)[]
|
||||
>x4 : (string | number)[]
|
||||
>f10(...u, ...v) : (string | number)[]
|
||||
>x4 : [...U, ...V]
|
||||
>f10(...u, ...v) : [...U, ...V]
|
||||
>f10 : <T extends unknown[]>(...args: T) => T
|
||||
>...u : string
|
||||
>u : U
|
||||
@@ -347,8 +347,8 @@ const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true]
|
||||
>t0 : []
|
||||
|
||||
const z18 = f11(...ns, true); // (string | number | true)[]
|
||||
>z18 : (string | number | true)[]
|
||||
>f11(...ns, true) : (string | number | true)[]
|
||||
>z18 : [number, string, true]
|
||||
>f11(...ns, true) : [number, string, true]
|
||||
>f11 : <T extends (string | number | boolean)[]>(...args: T) => T
|
||||
>...ns : string | number
|
||||
>ns : [number, string]
|
||||
@@ -374,16 +374,16 @@ function g11<U extends string[], V extends [number, number]>(u: U, v: V) {
|
||||
>v : V
|
||||
|
||||
let x3 = f11(1, ...u); // [1, ...string[]]
|
||||
>x3 : [1, ...string[]]
|
||||
>f11(1, ...u) : [1, ...string[]]
|
||||
>x3 : [1, ...U]
|
||||
>f11(1, ...u) : [1, ...U]
|
||||
>f11 : <T extends (string | number | boolean)[]>(...args: T) => T
|
||||
>1 : 1
|
||||
>...u : string
|
||||
>u : U
|
||||
|
||||
let x4 = f11(...u, ...v); // (string | number)[]
|
||||
>x4 : (string | number)[]
|
||||
>f11(...u, ...v) : (string | number)[]
|
||||
>x4 : [...U, ...V]
|
||||
>f11(...u, ...v) : [...U, ...V]
|
||||
>f11 : <T extends (string | number | boolean)[]>(...args: T) => T
|
||||
>...u : string
|
||||
>u : U
|
||||
|
||||
@@ -408,7 +408,7 @@ f20(42, "hello", ...t3);
|
||||
>t3 : boolean[]
|
||||
|
||||
f20(42, "hello", ...t2, true);
|
||||
>f20(42, "hello", ...t2, true) : [number, string, ...(string | boolean)[]]
|
||||
>f20(42, "hello", ...t2, true) : [number, string, string, ...boolean[]]
|
||||
>f20 : <T extends unknown[]>(...args: T) => T
|
||||
>42 : 42
|
||||
>"hello" : "hello"
|
||||
@@ -437,7 +437,7 @@ type T04 = ConstructorParameters<new (...args: [number, string, ...boolean[]]) =
|
||||
>args : [number, string, ...boolean[]]
|
||||
|
||||
type T05<T extends any[]> = Parameters<(x: string, ...args: T) => void>;
|
||||
>T05 : Parameters<(x: string, ...args: T) => void>
|
||||
>T05 : [x: string, ...args: T]
|
||||
>x : string
|
||||
>args : T
|
||||
|
||||
|
||||
@@ -2,18 +2,19 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(17,11): error TS234
|
||||
Type '[10]' is not assignable to type '[string]'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(18,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'.
|
||||
Type '[]' is missing the following properties from type '[number, boolean]': 0, 1
|
||||
Type '[]' is not assignable to type '[number, boolean]'.
|
||||
Source has 0 element(s) but target requires 2.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(22,1): error TS2322: Type '(x: string, ...args: [string] | [number, boolean]) => void' is not assignable to type '(...args: [string, string] | [string, number, boolean]) => void'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(23,1): error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
|
||||
Types of parameters 'y' and 'args' are incompatible.
|
||||
Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
|
||||
Type '[number, boolean]' is not assignable to type '[y: string]'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
Source has 2 element(s) but target allows only 1.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(24,1): error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
|
||||
Types of parameters 'y' and 'args' are incompatible.
|
||||
Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
|
||||
Property '1' is missing in type '[string]' but required in type '[y: number, z: boolean]'.
|
||||
Type '[string]' is not assignable to type '[y: number, z: boolean]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(25,1): error TS2322: Type '(...args: [string, string] | [string, number, boolean]) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(35,1): error TS2554: Expected 1 arguments, but got 0.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(36,21): error TS2345: Argument of type 'number' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
|
||||
@@ -31,7 +32,8 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(51,5): error TS2345
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(52,5): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'CoolArray<number>'.
|
||||
Property 'hello' is missing in type 'number[]' but required in type 'CoolArray<number>'.
|
||||
tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'.
|
||||
Property '1' is missing in type '["what"]' but required in type '[number, string]'.
|
||||
Type '["what"]' is not assignable to type '[number, string]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/genericRestParameters3.ts (15 errors) ====
|
||||
@@ -59,7 +61,8 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345
|
||||
f1("foo"); // Error
|
||||
~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'.
|
||||
!!! error TS2345: Type '[]' is missing the following properties from type '[number, boolean]': 0, 1
|
||||
!!! error TS2345: Type '[]' is not assignable to type '[number, boolean]'.
|
||||
!!! error TS2345: Source has 0 element(s) but target requires 2.
|
||||
|
||||
f2 = f1;
|
||||
f3 = f1;
|
||||
@@ -72,14 +75,14 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345
|
||||
!!! error TS2322: Types of parameters 'y' and 'args' are incompatible.
|
||||
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
|
||||
!!! error TS2322: Type '[number, boolean]' is not assignable to type '[y: string]'.
|
||||
!!! error TS2322: Types of property '0' are incompatible.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
!!! error TS2322: Source has 2 element(s) but target allows only 1.
|
||||
f1 = f3; // Error
|
||||
~~
|
||||
!!! error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
|
||||
!!! error TS2322: Types of parameters 'y' and 'args' are incompatible.
|
||||
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
|
||||
!!! error TS2322: Property '1' is missing in type '[string]' but required in type '[y: number, z: boolean]'.
|
||||
!!! error TS2322: Type '[string]' is not assignable to type '[y: number, z: boolean]'.
|
||||
!!! error TS2322: Source has 1 element(s) but target requires 2.
|
||||
f1 = f4; // Error, misaligned complex rest types
|
||||
~~
|
||||
!!! error TS2322: Type '(...args: [string, string] | [string, number, boolean]) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
|
||||
@@ -148,7 +151,8 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345
|
||||
hmm("what"); // no error? A = [] | [number, string] ?
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'.
|
||||
!!! error TS2345: Property '1' is missing in type '["what"]' but required in type '[number, string]'.
|
||||
!!! error TS2345: Type '["what"]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2345: Source has 1 element(s) but target requires 2.
|
||||
|
||||
// Repro from #35066
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/compiler/genericRestTypes.ts(21,11): error TS2322: Type '(cb: (x: string, ...rest: T) => void) => void' is not assignable to type '(cb: (...args: never) => void) => void'.
|
||||
Types of parameters 'cb' and 'cb' are incompatible.
|
||||
Types of parameters 'args' and 'x' are incompatible.
|
||||
Type '[x: string, ...rest: T[number][]]' is not assignable to type 'never'.
|
||||
Type '[x: string, ...rest: T]' is not assignable to type 'never'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/genericRestTypes.ts (1 errors) ====
|
||||
@@ -30,7 +30,7 @@ tests/cases/compiler/genericRestTypes.ts(21,11): error TS2322: Type '(cb: (x: st
|
||||
!!! error TS2322: Type '(cb: (x: string, ...rest: T) => void) => void' is not assignable to type '(cb: (...args: never) => void) => void'.
|
||||
!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible.
|
||||
!!! error TS2322: Types of parameters 'args' and 'x' are incompatible.
|
||||
!!! error TS2322: Type '[x: string, ...rest: T[number][]]' is not assignable to type 'never'.
|
||||
!!! error TS2322: Type '[x: string, ...rest: T]' is not assignable to type 'never'.
|
||||
}
|
||||
|
||||
function assignmentWithComplexRest3<T extends any[]>() {
|
||||
|
||||
@@ -7,8 +7,8 @@ tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(11,49): err
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(11,52): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(13,39): error TS5085: A tuple member cannot be both optional and rest.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(15,44): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(17,46): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(18,44): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(17,13): error TS2456: Type alias 'RecusiveRestUnlabeled' circularly references itself.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(18,13): error TS2456: Type alias 'RecusiveRest' circularly references itself.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts (11 errors) ====
|
||||
@@ -47,9 +47,9 @@ tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(18,44): err
|
||||
!!! error TS2574: A rest element type must be an array type.
|
||||
|
||||
export type RecusiveRestUnlabeled = [string, ...RecusiveRestUnlabeled];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2574: A rest element type must be an array type.
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2456: Type alias 'RecusiveRestUnlabeled' circularly references itself.
|
||||
export type RecusiveRest = [first: string, ...rest: RecusiveRest]; // marked as incorrect, same as above
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2574: A rest element type must be an array type.
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2456: Type alias 'RecusiveRest' circularly references itself.
|
||||
|
||||
@@ -3,7 +3,7 @@ export type Segment1 = [length: number, number]; // partially named, disallowed
|
||||
>Segment1 : Segment1
|
||||
|
||||
export type List = [item: any, ...any]; // partially named, disallowed
|
||||
>List : List
|
||||
>List : [any, ...any[]]
|
||||
|
||||
export type Pair = [item: any, any?]; // partially named, disallowed
|
||||
>Pair : Pair
|
||||
@@ -21,11 +21,11 @@ export type OptRest = [first: string, ...rest?: string[]]; // rest+optional disa
|
||||
>OptRest : OptRest
|
||||
|
||||
export type NonArrayRest = [first: string, ...rest: number]; // non-arraylike rest, disallowed
|
||||
>NonArrayRest : NonArrayRest
|
||||
>NonArrayRest : [first: string, ...rest: any[]]
|
||||
|
||||
export type RecusiveRestUnlabeled = [string, ...RecusiveRestUnlabeled];
|
||||
>RecusiveRestUnlabeled : RecusiveRestUnlabeled
|
||||
>RecusiveRestUnlabeled : any
|
||||
|
||||
export type RecusiveRest = [first: string, ...rest: RecusiveRest]; // marked as incorrect, same as above
|
||||
>RecusiveRest : RecusiveRest
|
||||
>RecusiveRest : any
|
||||
|
||||
@@ -2,7 +2,8 @@ tests/cases/compiler/namespaceDisambiguationInUnion.ts(10,7): error TS2322: Type
|
||||
Type '{ type: string; }' is not assignable to type 'Yep'.
|
||||
Types of property 'type' are incompatible.
|
||||
Type 'string' is not assignable to type '"bar.yep"'.
|
||||
tests/cases/compiler/namespaceDisambiguationInUnion.ts(13,7): error TS2739: Type '{ type: string; }[]' is missing the following properties from type '[Foo.Yep, Bar.Yep]': 0, 1
|
||||
tests/cases/compiler/namespaceDisambiguationInUnion.ts(13,7): error TS2322: Type '{ type: string; }[]' is not assignable to type '[Foo.Yep, Bar.Yep]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
|
||||
|
||||
==== tests/cases/compiler/namespaceDisambiguationInUnion.ts (2 errors) ====
|
||||
@@ -25,5 +26,6 @@ tests/cases/compiler/namespaceDisambiguationInUnion.ts(13,7): error TS2739: Type
|
||||
const y = [{ type: "a" }, { type: "b" }];
|
||||
const val2: [Foo.Yep, Bar.Yep] = y;
|
||||
~~~~
|
||||
!!! error TS2739: Type '{ type: string; }[]' is missing the following properties from type '[Foo.Yep, Bar.Yep]': 0, 1
|
||||
!!! error TS2322: Type '{ type: string; }[]' is not assignable to type '[Foo.Yep, Bar.Yep]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
|
||||
@@ -5,7 +5,7 @@ var c = {};
|
||||
|
||||
[...c] = ["", 0];
|
||||
>[...c] = ["", 0] : (string | number)[]
|
||||
>[...c] : undefined[]
|
||||
>[...c] : unknown[]
|
||||
>...c : any
|
||||
>c : {}
|
||||
>["", 0] : (string | number)[]
|
||||
|
||||
@@ -5,7 +5,7 @@ var c = {};
|
||||
|
||||
[...c] = ["", 0];
|
||||
>[...c] = ["", 0] : (string | number)[]
|
||||
>[...c] : undefined[]
|
||||
>[...c] : unknown[]
|
||||
>...c : any
|
||||
>c : {}
|
||||
>["", 0] : (string | number)[]
|
||||
|
||||
@@ -7,7 +7,7 @@ var c = { bogus: 0 };
|
||||
|
||||
[...c] = ["", 0];
|
||||
>[...c] = ["", 0] : (string | number)[]
|
||||
>[...c] : undefined[]
|
||||
>[...c] : unknown[]
|
||||
>...c : any
|
||||
>c : { bogus: number; }
|
||||
>["", 0] : (string | number)[]
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(11,29): error TS1257: A required element cannot follow an optional element.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(15,5): error TS2322: Type 'T2' is not assignable to type 'T1'.
|
||||
Types of property '2' are incompatible.
|
||||
Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
Property '2' is optional in type '[number, string, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(16,5): error TS2322: Type 'T3' is not assignable to type 'T1'.
|
||||
Types of property '1' are incompatible.
|
||||
Type 'string | undefined' is not assignable to type 'string'.
|
||||
Type 'undefined' is not assignable to type 'string'.
|
||||
Property '1' is optional in type '[number, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(17,5): error TS2322: Type 'T4' is not assignable to type 'T1'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'number | undefined' is not assignable to type 'number'.
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(20,5): error TS2322: Type 'T3' is not assignable to type 'T2'.
|
||||
Types of property '1' are incompatible.
|
||||
Type 'string | undefined' is not assignable to type 'string'.
|
||||
Type 'undefined' is not assignable to type 'string'.
|
||||
Property '1' is optional in type '[number, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, (boolean | undefined)?]'.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(21,5): error TS2322: Type 'T4' is not assignable to type 'T2'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'number | undefined' is not assignable to type 'number'.
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, (boolean | undefined)?]'.
|
||||
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(25,5): error TS2322: Type 'T4' is not assignable to type 'T3'.
|
||||
Types of property '0' are incompatible.
|
||||
Type 'number | undefined' is not assignable to type 'number'.
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, (string | undefined)?, (boolean | undefined)?]'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/optionalTupleElements1.ts (7 errors) ====
|
||||
@@ -45,44 +33,32 @@ tests/cases/conformance/types/tuple/optionalTupleElements1.ts(25,5): error TS232
|
||||
t1 = t2; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T2' is not assignable to type 'T1'.
|
||||
!!! error TS2322: Types of property '2' are incompatible.
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Property '2' is optional in type '[number, string, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
t1 = t3; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T3' is not assignable to type 'T1'.
|
||||
!!! error TS2322: Types of property '1' are incompatible.
|
||||
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Property '1' is optional in type '[number, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
t1 = t4; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T4' is not assignable to type 'T1'.
|
||||
!!! error TS2322: Types of property '0' are incompatible.
|
||||
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, boolean]'.
|
||||
t2 = t1;
|
||||
t2 = t2;
|
||||
t2 = t3; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T3' is not assignable to type 'T2'.
|
||||
!!! error TS2322: Types of property '1' are incompatible.
|
||||
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Property '1' is optional in type '[number, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, (boolean | undefined)?]'.
|
||||
t2 = t4; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T4' is not assignable to type 'T2'.
|
||||
!!! error TS2322: Types of property '0' are incompatible.
|
||||
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, string, (boolean | undefined)?]'.
|
||||
t3 = t1;
|
||||
t3 = t2;
|
||||
t3 = t3;
|
||||
t3 = t4; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T4' is not assignable to type 'T3'.
|
||||
!!! error TS2322: Types of property '0' are incompatible.
|
||||
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
||||
!!! error TS2322: Property '0' is optional in type '[(number | undefined)?, (string | undefined)?, (boolean | undefined)?]' but required in type '[number, (string | undefined)?, (boolean | undefined)?]'.
|
||||
t4 = t1;
|
||||
t4 = t2;
|
||||
t4 = t3;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type 'number' is not assignable to type '0'.
|
||||
Target allows only 0 element(s) but source may have more.
|
||||
|
||||
|
||||
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (1 errors) ====
|
||||
@@ -9,7 +8,6 @@ tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'a
|
||||
return emails;
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'any[]' is not assignable to type '[]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type 'number' is not assignable to type '0'.
|
||||
!!! error TS2322: Target allows only 0 element(s) but source may have more.
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ for (obj?.a.b of []);
|
||||
|
||||
[...obj?.a] = [];
|
||||
>[...obj?.a] = [] : never[]
|
||||
>[...obj?.a] : never[]
|
||||
>[...obj?.a] : any[]
|
||||
>...obj?.a : any
|
||||
>obj?.a : any
|
||||
>obj : any
|
||||
@@ -179,7 +179,7 @@ for (obj?.a.b of []);
|
||||
|
||||
[...obj?.a.b] = [];
|
||||
>[...obj?.a.b] = [] : never[]
|
||||
>[...obj?.a.b] : never[]
|
||||
>[...obj?.a.b] : any[]
|
||||
>...obj?.a.b : any
|
||||
>obj?.a.b : any
|
||||
>obj?.a : any
|
||||
|
||||
@@ -54,7 +54,7 @@ declare namespace Tools {
|
||||
T['length'];
|
||||
|
||||
type Prepend<E, T extends any[]> =
|
||||
>Prepend : Prepend<E, T>
|
||||
>Prepend : [head: E, ...args: T]
|
||||
|
||||
((head: E, ...args: T) => any) extends ((...args: infer U) => any)
|
||||
>head : E
|
||||
@@ -68,7 +68,7 @@ declare namespace Tools {
|
||||
>Drop : Drop<N, T, I>
|
||||
|
||||
0: Drop<N, Tail<T>, Prepend<any, I>>;
|
||||
>0 : Drop<N, Tail<T>, Prepend<any, I>>
|
||||
>0 : Drop<N, Tail<T>, [head: any, ...args: I]>
|
||||
|
||||
1: T;
|
||||
>1 : T
|
||||
@@ -88,7 +88,7 @@ declare namespace Tools {
|
||||
Length<I>;
|
||||
|
||||
type Next<I extends any[]> =
|
||||
>Next : Prepend<any, I>
|
||||
>Next : [head: any, ...args: I]
|
||||
|
||||
Prepend<any, I>;
|
||||
|
||||
@@ -101,7 +101,7 @@ declare namespace Tools {
|
||||
>Iterator : Iterator<Index, From, I>
|
||||
|
||||
0: Iterator<Index, Next<From>, Next<I>>;
|
||||
>0 : Iterator<Index, Prepend<any, From>, Prepend<any, I>>
|
||||
>0 : Iterator<Index, [head: any, ...args: From], [head: any, ...args: I]>
|
||||
|
||||
1: From;
|
||||
>1 : From
|
||||
@@ -116,7 +116,7 @@ declare namespace Tools {
|
||||
>Reverse : Reverse<T, R, I>
|
||||
|
||||
0: Reverse<T, Prepend<T[Pos<I>], R>, Next<I>>;
|
||||
>0 : Reverse<T, Prepend<T[Length<I>], R>, Prepend<any, I>>
|
||||
>0 : Reverse<T, [head: T[Length<I>], ...args: R], [head: any, ...args: I]>
|
||||
|
||||
1: R;
|
||||
>1 : R
|
||||
@@ -163,7 +163,7 @@ declare namespace Curry {
|
||||
|
||||
interface GapsOfWorker<T1 extends any[], T2 extends any[], TN extends any[] = [], I extends any[] = []> {
|
||||
0: GapsOf<T1, T2, GapOf<T1, T2, TN, I> extends infer G ? Tools.Cast<G, any[]> : never, Tools.Next<I>>;
|
||||
>0 : GapsOf<T1, T2, GapOf<T1, T2, TN, I> extends infer G ? Tools.Cast<G, any[]> : never, Tools.Prepend<any, I>>
|
||||
>0 : GapsOf<T1, T2, GapOf<T1, T2, TN, I> extends infer G ? Tools.Cast<G, any[]> : never, [head: any, ...args: I]>
|
||||
>Tools : any
|
||||
>Tools : any
|
||||
|
||||
|
||||
@@ -4,11 +4,14 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(11,12): error TS1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(12,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(15,5): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(17,5): error TS4104: The type 'readonly [string, string]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(21,5): error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(21,5): error TS2322: Type 'string[]' is not assignable to type '[string, string]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(22,5): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type '[string, string]'.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(23,5): error TS4104: The type 'readonly [string, string]' is 'readonly' and cannot be assigned to the mutable type '[string, string]'.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(25,5): error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2322: Type 'string[]' is not assignable to type 'readonly [string, string]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(25,5): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly [string, string]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(30,3): error TS2540: Cannot assign to '0' because it is a read-only property.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(31,3): error TS2540: Cannot assign to '1' because it is a read-only property.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(32,1): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading.
|
||||
@@ -53,7 +56,8 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(36,8): error TS25
|
||||
ra = rt;
|
||||
mt = ma; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
!!! error TS2322: Type 'string[]' is not assignable to type '[string, string]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
mt = ra; // Error
|
||||
~~
|
||||
!!! error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type '[string, string]'.
|
||||
@@ -62,10 +66,12 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(36,8): error TS25
|
||||
!!! error TS4104: The type 'readonly [string, string]' is 'readonly' and cannot be assigned to the mutable type '[string, string]'.
|
||||
rt = ma; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
!!! error TS2322: Type 'string[]' is not assignable to type 'readonly [string, string]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
rt = ra; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
!!! error TS2322: Type 'readonly string[]' is not assignable to type 'readonly [string, string]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
rt = mt;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,12 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(23,9): error TS2345: Ar
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(24,9): error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'.
|
||||
The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(27,7): error TS2322: Type 'readonly [1]' is not assignable to type 'readonly []'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '1' is not assignable to type '0'.
|
||||
Source has 1 element(s) but target allows only 0.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(30,7): error TS4104: The type 'readonly [1]' is 'readonly' and cannot be assigned to the mutable type '[]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(33,7): error TS2322: Type '[1]' is not assignable to type 'readonly []'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '1' is not assignable to type '0'.
|
||||
Source has 1 element(s) but target allows only 0.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(36,7): error TS2322: Type '[1]' is not assignable to type '[]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '1' is not assignable to type '0'.
|
||||
Source has 1 element(s) but target allows only 0.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(39,7): error TS2322: Type 'readonly number[]' is not assignable to type 'readonly boolean[]'.
|
||||
Type 'number' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(42,7): error TS4104: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'boolean[]'.
|
||||
@@ -34,10 +31,13 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(57,7): error TS2322: Ty
|
||||
Type '1' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(60,7): error TS2322: Type '[1]' is not assignable to type 'boolean[]'.
|
||||
Type '1' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(63,7): error TS2741: Property '0' is missing in type 'readonly number[]' but required in type 'readonly [1]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(63,7): error TS2322: Type 'readonly number[]' is not assignable to type 'readonly [1]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(66,7): error TS4104: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type '[1]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(69,7): error TS2741: Property '0' is missing in type 'number[]' but required in type 'readonly [1]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Property '0' is missing in type 'number[]' but required in type '[1]'.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(69,7): error TS2322: Type 'number[]' is not assignable to type 'readonly [1]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2322: Type 'number[]' is not assignable to type '[1]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
|
||||
==== tests/cases/compiler/readonlyTupleAndArrayElaboration.ts (22 errors) ====
|
||||
@@ -88,8 +88,7 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Pr
|
||||
const t2: readonly [] = t1;
|
||||
~~
|
||||
!!! error TS2322: Type 'readonly [1]' is not assignable to type 'readonly []'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '1' is not assignable to type '0'.
|
||||
!!! error TS2322: Source has 1 element(s) but target allows only 0.
|
||||
|
||||
const t3: readonly [1] = [1];
|
||||
const t4: [] = t3;
|
||||
@@ -100,15 +99,13 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Pr
|
||||
const t6: readonly [] = t5;
|
||||
~~
|
||||
!!! error TS2322: Type '[1]' is not assignable to type 'readonly []'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '1' is not assignable to type '0'.
|
||||
!!! error TS2322: Source has 1 element(s) but target allows only 0.
|
||||
|
||||
const t7: [1] = [1];
|
||||
const t8: [] = t7;
|
||||
~~
|
||||
!!! error TS2322: Type '[1]' is not assignable to type '[]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '1' is not assignable to type '0'.
|
||||
!!! error TS2322: Source has 1 element(s) but target allows only 0.
|
||||
|
||||
const a1: readonly number[] = [1];
|
||||
const a2: readonly boolean[] = a1;
|
||||
@@ -159,7 +156,8 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Pr
|
||||
const at1: readonly number[] = [1];
|
||||
const at2: readonly [1] = at1;
|
||||
~~~
|
||||
!!! error TS2741: Property '0' is missing in type 'readonly number[]' but required in type 'readonly [1]'.
|
||||
!!! error TS2322: Type 'readonly number[]' is not assignable to type 'readonly [1]'.
|
||||
!!! error TS2322: Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
const at3: readonly number[] = [1];
|
||||
const at4: [1] = at3;
|
||||
@@ -169,10 +167,12 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Pr
|
||||
const at5: number[] = [1];
|
||||
const at6: readonly [1] = at5;
|
||||
~~~
|
||||
!!! error TS2741: Property '0' is missing in type 'number[]' but required in type 'readonly [1]'.
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type 'readonly [1]'.
|
||||
!!! error TS2322: Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
const at7: number[] = [1];
|
||||
const at8: [1] = at7;
|
||||
~~~
|
||||
!!! error TS2741: Property '0' is missing in type 'number[]' but required in type '[1]'.
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[1]'.
|
||||
!!! error TS2322: Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,49): error TS2577: Return type annotation circularly references itself.
|
||||
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,58): error TS2304: Cannot find name 'H'.
|
||||
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,62): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/compiler/recursiveResolveTypeMembers.ts(4,79): error TS2304: Cannot find name 'R'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/recursiveResolveTypeMembers.ts (4 errors) ====
|
||||
==== tests/cases/compiler/recursiveResolveTypeMembers.ts (3 errors) ====
|
||||
// Repro from #25291
|
||||
|
||||
type PromisedTuple<L extends any[], U = (...args: L) => void> =
|
||||
@@ -13,8 +12,6 @@ tests/cases/compiler/recursiveResolveTypeMembers.ts(4,79): error TS2304: Cannot
|
||||
!!! error TS2577: Return type annotation circularly references itself.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'H'.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2574: A rest element type must be an array type.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'R'.
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ var a: string, b: number;
|
||||
|
||||
[...{ 0: a = "", b }] = ["", 1];
|
||||
>[...{ 0: a = "", b }] = ["", 1] : (string | number)[]
|
||||
>[...{ 0: a = "", b }] : undefined[]
|
||||
>[...{ 0: a = "", b }] : unknown[]
|
||||
>...{ 0: a = "", b } : any
|
||||
>{ 0: a = "", b } : { 0?: string; b: number; }
|
||||
>0 : string
|
||||
|
||||
@@ -11,7 +11,7 @@ var tuple: [string, number] = ["", 1];
|
||||
|
||||
[...{ 0: a = "", b }] = tuple;
|
||||
>[...{ 0: a = "", b }] = tuple : [string, number]
|
||||
>[...{ 0: a = "", b }] : undefined[]
|
||||
>[...{ 0: a = "", b }] : unknown[]
|
||||
>...{ 0: a = "", b } : any
|
||||
>{ 0: a = "", b } : { 0?: string; b: number; }
|
||||
>0 : string
|
||||
|
||||
@@ -4,26 +4,25 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(9,13): error TS2574: A
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,13): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,16): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(23,31): error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Property '0' is missing in type 'number[]' but required in type '[number, ...number[]]'.
|
||||
Property '0' is optional in type 'number[]' but required in type '[number, ...number[]]'.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(24,31): error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Property '0' is missing in type '[]' but required in type '[number, ...number[]]'.
|
||||
Source has 0 element(s) but target requires 1.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(29,18): error TS2344: Type 'number[]' does not satisfy the constraint '[number]'.
|
||||
Property '0' is missing in type 'number[]' but required in type '[number]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(30,18): error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type 'number' is not assignable to type '1'.
|
||||
Target allows only 1 element(s) but source may have more.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(32,31): error TS2344: Type '[number, ...string[]]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(33,31): error TS2344: Type '[string, ...number[]]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(34,31): error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Property '2' is incompatible with rest element type.
|
||||
Types of property '2' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(35,31): error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Property '3' is incompatible with rest element type.
|
||||
Types of property '3' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[]]'.
|
||||
Property '0' is missing in type '[]' but required in type '[unknown, ...unknown[]]'.
|
||||
Source has 0 element(s) but target requires 1.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/restTupleElements1.ts (14 errors) ====
|
||||
@@ -62,11 +61,11 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: A
|
||||
assign<[number, ...number[]], number[]>(); // Error
|
||||
~~~~~~~~
|
||||
!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
!!! error TS2344: Property '0' is missing in type 'number[]' but required in type '[number, ...number[]]'.
|
||||
!!! error TS2344: Property '0' is optional in type 'number[]' but required in type '[number, ...number[]]'.
|
||||
assign<[number, ...number[]], []>(); // Error
|
||||
~~
|
||||
!!! error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
!!! error TS2344: Property '0' is missing in type '[]' but required in type '[number, ...number[]]'.
|
||||
!!! error TS2344: Source has 0 element(s) but target requires 1.
|
||||
assign<[number, ...number[]], [number]>();
|
||||
assign<[number, ...number[]], [number, number]>();
|
||||
assign<[number, ...number[]], [number, number, ...number[]]>();
|
||||
@@ -74,12 +73,11 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: A
|
||||
assign<[number], [...number[]]>(); // Error
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number]'.
|
||||
!!! error TS2344: Property '0' is missing in type 'number[]' but required in type '[number]'.
|
||||
!!! error TS2344: Target requires 1 element(s) but source may have fewer.
|
||||
assign<[number], [number, ...number[]]>(); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'.
|
||||
!!! error TS2344: Types of property 'length' are incompatible.
|
||||
!!! error TS2344: Type 'number' is not assignable to type '1'.
|
||||
!!! error TS2344: Target allows only 1 element(s) but source may have more.
|
||||
|
||||
assign<[number, ...number[]], [number, ...string[]]>(); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -92,12 +90,12 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: A
|
||||
assign<[number, ...number[]], [number, number, string]>(); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
!!! error TS2344: Property '2' is incompatible with rest element type.
|
||||
!!! error TS2344: Types of property '2' are incompatible.
|
||||
!!! error TS2344: Type 'string' is not assignable to type 'number'.
|
||||
assign<[number, ...number[]], [number, number, number, string]>(); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
!!! error TS2344: Property '3' is incompatible with rest element type.
|
||||
!!! error TS2344: Types of property '3' are incompatible.
|
||||
!!! error TS2344: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
type T20 = [number, string, ...boolean[]];
|
||||
@@ -125,7 +123,7 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: A
|
||||
f0([]); // Error
|
||||
~~
|
||||
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[]]'.
|
||||
!!! error TS2345: Property '0' is missing in type '[]' but required in type '[unknown, ...unknown[]]'.
|
||||
!!! error TS2345: Source has 0 element(s) but target requires 1.
|
||||
f0([1]);
|
||||
f0([1, 2, 3]);
|
||||
f0([1, "hello", true]);
|
||||
|
||||
@@ -24,10 +24,10 @@ type T07 = [...string[], string]; // Error
|
||||
>T07 : T07
|
||||
|
||||
type T08 = [...string]; // Error
|
||||
>T08 : T08
|
||||
>T08 : any[]
|
||||
|
||||
type T09 = [...string?]; // Error
|
||||
>T09 : T09
|
||||
>T09 : any[]
|
||||
|
||||
type T10 = [string, ...[...string[]]];
|
||||
>T10 : T10
|
||||
@@ -107,7 +107,7 @@ type T21 = T20[0];
|
||||
>T21 : number
|
||||
|
||||
type T22 = T20[0 | 1];
|
||||
>T22 : string | number
|
||||
>T22 : T22
|
||||
|
||||
type T23 = T20[0 | 1 | 2];
|
||||
>T23 : string | number | boolean
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error TS2345: Argument of type '(a: number, b: T[0], ...x: T[number][]) => void' is not assignable to parameter of type '(x: number, ...args: T) => void'.
|
||||
Types of parameters 'b' and 'args' are incompatible.
|
||||
Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'.
|
||||
Property '0' is missing in type 'any[]' but required in type '[b: T[0], ...x: T[number][]]'.
|
||||
Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'.
|
||||
Property '0' is optional in type 'any[]' but required in type '[b: T[0], ...x: T[number][]]'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts (1 errors) ====
|
||||
@@ -65,7 +66,8 @@ tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error
|
||||
!!! error TS2345: Argument of type '(a: number, b: T[0], ...x: T[number][]) => void' is not assignable to parameter of type '(x: number, ...args: T) => void'.
|
||||
!!! error TS2345: Types of parameters 'b' and 'args' are incompatible.
|
||||
!!! error TS2345: Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'.
|
||||
!!! error TS2345: Property '0' is missing in type 'any[]' but required in type '[b: T[0], ...x: T[number][]]'.
|
||||
!!! error TS2345: Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'.
|
||||
!!! error TS2345: Property '0' is optional in type 'any[]' but required in type '[b: T[0], ...x: T[number][]]'.
|
||||
}
|
||||
|
||||
declare function f5<T extends any[], U>(f: (...args: T) => U): (...args: T) => U;
|
||||
|
||||
@@ -314,10 +314,10 @@ function f4<T extends any[]>(t: T) {
|
||||
|
||||
(function(a, ...x){})(1, 2, ...t);
|
||||
>(function(a, ...x){})(1, 2, ...t) : void
|
||||
>(function(a, ...x){}) : (a: number, x_0: number, ...x_1: any[]) => void
|
||||
>function(a, ...x){} : (a: number, x_0: number, ...x_1: any[]) => void
|
||||
>(function(a, ...x){}) : (a: number, x_0: number, ...x_1: T) => void
|
||||
>function(a, ...x){} : (a: number, x_0: number, ...x_1: T) => void
|
||||
>a : number
|
||||
>x : [number, ...any[]]
|
||||
>x : [number, ...T]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>...t : any
|
||||
@@ -332,8 +332,8 @@ function f4<T extends any[]>(t: T) {
|
||||
f((...x) => {});
|
||||
>f((...x) => {}) : void
|
||||
>f : (cb: (x: number, ...args: T) => void) => void
|
||||
>(...x) => {} : (x: number, ...args: T[number][]) => void
|
||||
>x : [x: number, ...args: T[number][]]
|
||||
>(...x) => {} : (x: number, ...args: T) => void
|
||||
>x : [x: number, ...args: T]
|
||||
|
||||
f((a, ...x) => {});
|
||||
>f((a, ...x) => {}) : void
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
tests/cases/compiler/restTypeRetainsMappyness.ts(7,8): error TS2345: Argument of type 'Foo<T>[number][]' is not assignable to parameter of type 'Foo<T>'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restTypeRetainsMappyness.ts (1 errors) ====
|
||||
type Foo<T extends any[]> = {
|
||||
[P in keyof T]: T[P]
|
||||
}
|
||||
|
||||
function test<T extends any[]>(fn: (...args: Foo<T>) => void) {
|
||||
const arr: Foo<T> = {} as any
|
||||
fn(...arr) // Error: Argument of type 'any[]' is not assignable to parameter of type 'Foo<T>'
|
||||
~~~~~~
|
||||
!!! error TS2345: Argument of type 'Foo<T>[number][]' is not assignable to parameter of type 'Foo<T>'.
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
tests/cases/compiler/spliceTuples.ts(23,1): error TS2741: Property '3' is missing in type '[number, string, boolean, ...boolean[]]' but required in type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
tests/cases/compiler/spliceTuples.ts(23,1): error TS2322: Type '[number, string, boolean, ...boolean[]]' is not assignable to type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
Property '3' is optional in type '[number, string, boolean, ...boolean[]]' but required in type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/spliceTuples.ts (1 errors) ====
|
||||
@@ -26,5 +27,6 @@ tests/cases/compiler/spliceTuples.ts(23,1): error TS2741: Property '3' is missin
|
||||
let k6: [number, string, boolean, boolean, ...boolean[]];
|
||||
k6 = [1, ...sbb_];
|
||||
~~
|
||||
!!! error TS2741: Property '3' is missing in type '[number, string, boolean, ...boolean[]]' but required in type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
!!! error TS2322: Type '[number, string, boolean, ...boolean[]]' is not assignable to type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
!!! error TS2322: Property '3' is optional in type '[number, string, boolean, ...boolean[]]' but required in type '[number, string, boolean, boolean, ...boolean[]]'.
|
||||
|
||||
@@ -10,11 +10,10 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(17,15): error TS2554:
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(18,35): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(19,44): error TS2554: Expected 3 arguments, but got 4.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(22,32): error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(23,37): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(24,32): error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(41,11): error TS2769: No overload matches this call.
|
||||
Overload 1 of 6, '(this: (this: C, arg0: 10, arg1: string) => string, thisArg: C, arg0: 10, arg1: string): () => string', gave the following error.
|
||||
Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
@@ -36,11 +35,10 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(49,29): error TS2345:
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(50,38): error TS2554: Expected 3 arguments, but got 4.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(51,22): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'C'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(54,26): error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(55,31): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(56,26): error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(57,23): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'C'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(62,11): error TS2769: No overload matches this call.
|
||||
Overload 1 of 6, '(this: new (arg0: 10, arg1: string) => C, thisArg: any, arg0: 10, arg1: string): new () => C', gave the following error.
|
||||
@@ -54,11 +52,10 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(65,3): error TS2554: E
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(66,15): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(67,24): error TS2554: Expected 3 arguments, but got 4.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(70,12): error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(71,17): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/functions/strictBindCallApply1.ts(72,12): error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/strictBindCallApply1.ts (24 errors) ====
|
||||
@@ -101,15 +98,14 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(72,12): error TS2345:
|
||||
let a01 = foo.apply(undefined, [10]); // Error
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
!!! error TS2345: Source has 1 element(s) but target requires 2.
|
||||
let a02 = foo.apply(undefined, [10, 20]); // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
let a03 = foo.apply(undefined, [10, "hello", 30]); // Error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2345: Source has 3 element(s) but target allows only 2.
|
||||
|
||||
class C {
|
||||
constructor(a: number, b: string) {}
|
||||
@@ -168,15 +164,14 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(72,12): error TS2345:
|
||||
let a11 = c.foo.apply(c, [10]); // Error
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
!!! error TS2345: Source has 1 element(s) but target requires 2.
|
||||
let a12 = c.foo.apply(c, [10, 20]); // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
let a13 = c.foo.apply(c, [10, "hello", 30]); // Error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2345: Source has 3 element(s) but target allows only 2.
|
||||
let a14 = c.foo.apply(undefined, [10, "hello"]); // Error
|
||||
~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'C'.
|
||||
@@ -210,13 +205,12 @@ tests/cases/conformance/functions/strictBindCallApply1.ts(72,12): error TS2345:
|
||||
C.apply(c, [10]); // Error
|
||||
~~~~
|
||||
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Property '1' is missing in type '[number]' but required in type '[a: number, b: string]'.
|
||||
!!! error TS2345: Source has 1 element(s) but target requires 2.
|
||||
C.apply(c, [10, 20]); // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
C.apply(c, [10, "hello", 30]); // Error
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
|
||||
!!! error TS2345: Types of property 'length' are incompatible.
|
||||
!!! error TS2345: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2345: Source has 3 element(s) but target allows only 2.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
tests/cases/conformance/types/tuple/strictTupleLength.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't1' must be of type '[number]', but here has type '[number, number]'.
|
||||
tests/cases/conformance/types/tuple/strictTupleLength.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type '[number, number]', but here has type '[number]'.
|
||||
tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2741: Property '0' is missing in type 'number[]' but required in type '[number]'.
|
||||
tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2322: Type 'number[]' is not assignable to type '[number]'.
|
||||
Target requires 1 element(s) but source may have fewer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/strictTupleLength.ts (3 errors) ====
|
||||
@@ -29,6 +30,7 @@ tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2741: Pr
|
||||
|
||||
t1 = arr; // error with or without strict
|
||||
~~
|
||||
!!! error TS2741: Property '0' is missing in type 'number[]' but required in type '[number]'.
|
||||
!!! error TS2322: Type 'number[]' is not assignable to type '[number]'.
|
||||
!!! error TS2322: Target requires 1 element(s) but source may have fewer.
|
||||
arr = t1; // ok with or without strict
|
||||
|
||||
@@ -14,7 +14,7 @@ let c, d;
|
||||
([...c,] = []);
|
||||
>([...c,] = []) : undefined[]
|
||||
>[...c,] = [] : undefined[]
|
||||
>[...c,] : undefined[]
|
||||
>[...c,] : any[]
|
||||
>...c : any
|
||||
>c : any
|
||||
>[] : undefined[]
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
tests/cases/compiler/tupleTypes.ts(11,12): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
|
||||
tests/cases/compiler/tupleTypes.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'undefined', but here has type 'string | number'.
|
||||
tests/cases/compiler/tupleTypes.ts(14,1): error TS2739: Type '[]' is missing the following properties from type '[number, string]': 0, 1
|
||||
tests/cases/compiler/tupleTypes.ts(15,1): error TS2741: Property '1' is missing in type '[number]' but required in type '[number, string]'.
|
||||
tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '[]' is not assignable to type '[number, string]'.
|
||||
Source has 0 element(s) but target requires 2.
|
||||
tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]'.
|
||||
Source has 1 element(s) but target requires 2.
|
||||
tests/cases/compiler/tupleTypes.ts(17,6): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/tupleTypes.ts(17,15): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/tupleTypes.ts(18,1): error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
tests/cases/compiler/tupleTypes.ts(35,14): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
|
||||
tests/cases/compiler/tupleTypes.ts(36,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'undefined', but here has type 'string | number'.
|
||||
tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type '[]' is not assignable to type '[number, string]'.
|
||||
@@ -43,10 +44,12 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n
|
||||
|
||||
t = []; // Error
|
||||
~
|
||||
!!! error TS2739: Type '[]' is missing the following properties from type '[number, string]': 0, 1
|
||||
!!! error TS2322: Type '[]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Source has 0 element(s) but target requires 2.
|
||||
t = [1]; // Error
|
||||
~
|
||||
!!! error TS2741: Property '1' is missing in type '[number]' but required in type '[number, string]'.
|
||||
!!! error TS2322: Type '[number]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Source has 1 element(s) but target requires 2.
|
||||
t = [1, "hello"]; // Ok
|
||||
t = ["hello", 1]; // Error
|
||||
~~~~~~~
|
||||
@@ -56,8 +59,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n
|
||||
t = [1, "hello", 2]; // Error
|
||||
~
|
||||
!!! error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
|
||||
var tf: [string, (x: string) => number] = ["hello", x => x.length];
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts(9,5): error TS2322: Type '[number, string, string]' is not assignable to type '[number, string]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '3' is not assignable to type '2'.
|
||||
Source has 3 element(s) but target allows only 2.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts (1 errors) ====
|
||||
@@ -15,8 +14,7 @@ tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts(9,5): error TS2
|
||||
var arr4Tuple: [number, string] = [3, "three", "hello"]; // [number, string, string]
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type '[number, string, string]' is not assignable to type '[number, string]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '3' is not assignable to type '2'.
|
||||
!!! error TS2322: Source has 3 element(s) but target allows only 2.
|
||||
var arrEmpty = [];
|
||||
var arr5Tuple: {
|
||||
0: string;
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(6,48): error TS1256: A rest element must be last in a tuple type.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(46,5): error TS2555: Expected at least 3 arguments, but got 2.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(47,17): error TS2345: Argument of type '45' is not assignable to parameter of type 'boolean'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(125,9): error TS2344: Type 'V' does not satisfy the constraint 'unknown[]'.
|
||||
The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type 'unknown[]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(143,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(145,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'.
|
||||
Target requires 2 element(s) but source may have fewer.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(146,5): error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string[]'.
|
||||
Type 'string[]' is not assignable to type 'U'.
|
||||
'U' could be instantiated with an arbitrary type which could be unrelated to 'string[]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(154,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
|
||||
'T' could be instantiated with an arbitrary type which could be unrelated to 'readonly [...T]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(156,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(163,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
|
||||
'readonly [...T]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'readonly unknown[]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(164,5): error TS2322: Type 'T' is not assignable to type '[...T]'.
|
||||
The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(165,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
tests/cases/conformance/types/tuple/variadicTuples1.ts(297,14): error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/variadicTuples1.ts (13 errors) ====
|
||||
// Variadics in tuple types
|
||||
|
||||
type TV0<T extends unknown[]> = [string, ...T];
|
||||
type TV1<T extends unknown[]> = [string, ...T, number];
|
||||
type TV2<T extends unknown[]> = [string, ...T, number, ...T];
|
||||
type TV3<T extends unknown[]> = [string, ...T, ...number[], ...T]; // Error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1256: A rest element must be last in a tuple type.
|
||||
|
||||
// Normalization
|
||||
|
||||
type TN1 = TV1<[boolean, string]>;
|
||||
type TN2 = TV1<[]>;
|
||||
type TN3 = TV1<[boolean?]>;
|
||||
type TN4 = TV1<string[]>;
|
||||
type TN5 = TV1<[boolean] | [symbol, symbol]>;
|
||||
type TN6 = TV1<any>;
|
||||
type TN7 = TV1<never>;
|
||||
|
||||
// Variadics in array literals
|
||||
|
||||
function tup2<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]) {
|
||||
return [1, ...t, 2, ...u, 3] as const;
|
||||
}
|
||||
|
||||
const t2 = tup2(['hello'], [10, true]);
|
||||
|
||||
function concat<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): [...T, ...U] {
|
||||
return [...t, ...u];
|
||||
}
|
||||
|
||||
declare const sa: string[];
|
||||
|
||||
const tc1 = concat([], []);
|
||||
const tc2 = concat(['hello'], [42]);
|
||||
const tc3 = concat([1, 2, 3], sa);
|
||||
const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
|
||||
|
||||
// Spread arguments
|
||||
|
||||
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
|
||||
|
||||
function foo2(t1: [number, string], t2: [boolean], a1: number[]) {
|
||||
foo1(1, 'abc', true, 42, 43, 44);
|
||||
foo1(...t1, true, 42, 43, 44);
|
||||
foo1(...t1, ...t2, 42, 43, 44);
|
||||
foo1(...t1, ...t2, ...a1);
|
||||
foo1(...t1); // Error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2555: Expected at least 3 arguments, but got 2.
|
||||
!!! related TS6210 tests/cases/conformance/types/tuple/variadicTuples1.ts:39:45: An argument for 'c' was not provided.
|
||||
foo1(...t1, 45); // Error
|
||||
~~
|
||||
!!! error TS2345: Argument of type '45' is not assignable to parameter of type 'boolean'.
|
||||
}
|
||||
|
||||
declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T;
|
||||
|
||||
function foo4<U extends unknown[]>(u: U) {
|
||||
foo3(1, 2);
|
||||
foo3(1, 'hello', true, 2);
|
||||
foo3(1, ...u, 'hi', 2);
|
||||
foo3(1);
|
||||
}
|
||||
|
||||
// Contextual typing of array literals
|
||||
|
||||
declare function ft1<T extends unknown[]>(t: T): T;
|
||||
declare function ft2<T extends unknown[]>(t: T): readonly [...T];
|
||||
declare function ft3<T extends unknown[]>(t: [...T]): T;
|
||||
declare function ft4<T extends unknown[]>(t: [...T]): readonly [...T];
|
||||
|
||||
ft1(['hello', 42]); // (string | number)[]
|
||||
ft2(['hello', 42]); // readonly (string | number)[]
|
||||
ft3(['hello', 42]); // [string, number]
|
||||
ft4(['hello', 42]); // readonly [string, number]
|
||||
|
||||
// Indexing variadic tuple types
|
||||
|
||||
function f0<T extends unknown[]>(t: [string, ...T], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T][1]
|
||||
const c = t[2]; // [string, ...T][2]
|
||||
const d = t[n]; // [string, ...T][number]
|
||||
}
|
||||
|
||||
function f1<T extends unknown[]>(t: [string, ...T, number], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T, number][1]
|
||||
const c = t[2]; // [string, ...T, number][2]
|
||||
const d = t[n]; // [string, ...T, number][number]
|
||||
}
|
||||
|
||||
// Destructuring variadic tuple types
|
||||
|
||||
function f2<T extends unknown[]>(t: [string, ...T]) {
|
||||
let [...ax] = t; // [string, ...T]
|
||||
let [b1, ...bx] = t; // string, [...T]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T][1], T[number][]
|
||||
}
|
||||
|
||||
function f3<T extends unknown[]>(t: [string, ...T, number]) {
|
||||
let [...ax] = t; // [string, ...T, number]
|
||||
let [b1, ...bx] = t; // string, [...T, number]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T, number][1], (number | T[number])[]
|
||||
}
|
||||
|
||||
// Mapped types applied to variadic tuple types
|
||||
|
||||
type Arrayify<T> = { [P in keyof T]: T[P][] };
|
||||
|
||||
type TM1<U extends unknown[]> = Arrayify<readonly [string, number?, ...U, ...boolean[]]>; // [string[], (number | undefined)[]?, Arrayify<U>, ...boolean[][]]
|
||||
|
||||
type TP1<T extends unknown[]> = Partial<[string, ...T, number]>; // [string?, Partial<T>, number?]
|
||||
type TP2<T extends unknown[]> = Partial<[string, ...T, ...number[]]>; // [string?, Partial<T>, ...(number | undefined)[]]
|
||||
|
||||
// Reverse mapping through mapped type applied to variadic tuple type
|
||||
|
||||
declare function fm1<T extends unknown[]>(t: Arrayify<[string, number, ...T]>): T;
|
||||
|
||||
let tm1 = fm1([['abc'], [42], [true], ['def']]); // [boolean, string]
|
||||
|
||||
// Spread of readonly array-like infers mutable array-like
|
||||
|
||||
declare function fx1<T extends unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx1<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx1('abc'); // []
|
||||
fx1('abc', ...u); // U
|
||||
fx1('abc', ...v); // [...V]
|
||||
fx1<U>('abc', ...u); // U
|
||||
fx1<V>('abc', ...v); // Error
|
||||
~
|
||||
!!! error TS2344: Type 'V' does not satisfy the constraint 'unknown[]'.
|
||||
!!! error TS2344: The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type 'unknown[]'.
|
||||
}
|
||||
|
||||
declare function fx2<T extends readonly unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx2<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx2('abc'); // []
|
||||
fx2('abc', ...u); // U
|
||||
fx2('abc', ...v); // [...V]
|
||||
fx2<U>('abc', ...u); // U
|
||||
fx2<V>('abc', ...v); // V
|
||||
}
|
||||
|
||||
// Relations involving variadic tuple types
|
||||
|
||||
function f10<T extends string[], U extends T>(x: [string, ...unknown[]], y: [string, ...T], z: [string, ...U]) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
y = z;
|
||||
z = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'.
|
||||
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
|
||||
z = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'.
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'U'.
|
||||
!!! error TS2322: 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string[]'.
|
||||
!!! error TS2322: Type 'string[]' is not assignable to type 'U'.
|
||||
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'string[]'.
|
||||
}
|
||||
|
||||
// For a generic type T, [...T] is assignable to T, T is assignable to readonly [...T], and T is assignable
|
||||
// to [...T] when T is constrained to a mutable array or tuple type.
|
||||
|
||||
function f11<T extends unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
|
||||
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'readonly [...T]'.
|
||||
m = t;
|
||||
m = r; // Error
|
||||
~
|
||||
!!! error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
|
||||
!!! error TS2322: 'readonly [...T]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'readonly unknown[]'.
|
||||
m = t; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'T' is not assignable to type '[...T]'.
|
||||
!!! error TS2322: The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
m = r; // Error
|
||||
~
|
||||
!!! error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
// Inference between variadic tuple types
|
||||
|
||||
type First<T extends readonly unknown[]> = T[0];
|
||||
type DropFirst<T extends readonly unknown[]> = T extends readonly [any, ...infer U] ? U : [...T];
|
||||
|
||||
type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : undefined;
|
||||
type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any] ? U : [...T];
|
||||
|
||||
type T00 = First<[number, symbol, string]>;
|
||||
type T01 = First<[symbol, string]>;
|
||||
type T02 = First<[string]>;
|
||||
type T03 = First<[number, symbol, ...string[]]>;
|
||||
type T04 = First<[symbol, ...string[]]>;
|
||||
type T05 = First<string[]>;
|
||||
type T06 = First<[]>;
|
||||
type T07 = First<any>;
|
||||
type T08 = First<never>;
|
||||
|
||||
type T10 = DropFirst<[number, symbol, string]>;
|
||||
type T11 = DropFirst<[symbol, string]>;
|
||||
type T12 = DropFirst<[string]>;
|
||||
type T13 = DropFirst<[number, symbol, ...string[]]>;
|
||||
type T14 = DropFirst<[symbol, ...string[]]>;
|
||||
type T15 = DropFirst<string[]>;
|
||||
type T16 = DropFirst<[]>;
|
||||
type T17 = DropFirst<any>;
|
||||
type T18 = DropFirst<never>;
|
||||
|
||||
type T20 = Last<[number, symbol, string]>;
|
||||
type T21 = Last<[symbol, string]>;
|
||||
type T22 = Last<[string]>;
|
||||
type T23 = Last<[number, symbol, ...string[]]>;
|
||||
type T24 = Last<[symbol, ...string[]]>;
|
||||
type T25 = Last<string[]>;
|
||||
type T26 = Last<[]>; // unknown[], maybe should be []
|
||||
type T27 = Last<any>; // unknown, maybe should be any
|
||||
type T28 = Last<never>;
|
||||
|
||||
type T30 = DropLast<[number, symbol, string]>;
|
||||
type T31 = DropLast<[symbol, string]>;
|
||||
type T32 = DropLast<[string]>;
|
||||
type T33 = DropLast<[number, symbol, ...string[]]>;
|
||||
type T34 = DropLast<[symbol, ...string[]]>;
|
||||
type T35 = DropLast<string[]>;
|
||||
type T36 = DropLast<[]>; // unknown[], maybe should be []
|
||||
type T37 = DropLast<any>;
|
||||
type T38 = DropLast<never>;
|
||||
|
||||
type R00 = First<readonly [number, symbol, string]>;
|
||||
type R01 = First<readonly [symbol, string]>;
|
||||
type R02 = First<readonly [string]>;
|
||||
type R03 = First<readonly [number, symbol, ...string[]]>;
|
||||
type R04 = First<readonly [symbol, ...string[]]>;
|
||||
type R05 = First<readonly string[]>;
|
||||
type R06 = First<readonly []>;
|
||||
|
||||
type R10 = DropFirst<readonly [number, symbol, string]>;
|
||||
type R11 = DropFirst<readonly [symbol, string]>;
|
||||
type R12 = DropFirst<readonly [string]>;
|
||||
type R13 = DropFirst<readonly [number, symbol, ...string[]]>;
|
||||
type R14 = DropFirst<readonly [symbol, ...string[]]>;
|
||||
type R15 = DropFirst<readonly string[]>;
|
||||
type R16 = DropFirst<readonly []>;
|
||||
|
||||
type R20 = Last<readonly [number, symbol, string]>;
|
||||
type R21 = Last<readonly [symbol, string]>;
|
||||
type R22 = Last<readonly [string]>;
|
||||
type R23 = Last<readonly [number, symbol, ...string[]]>;
|
||||
type R24 = Last<readonly [symbol, ...string[]]>;
|
||||
type R25 = Last<readonly string[]>;
|
||||
type R26 = Last<readonly []>;
|
||||
|
||||
type R30 = DropLast<readonly [number, symbol, string]>;
|
||||
type R31 = DropLast<readonly [symbol, string]>;
|
||||
type R32 = DropLast<readonly [string]>;
|
||||
type R33 = DropLast<readonly [number, symbol, ...string[]]>;
|
||||
type R34 = DropLast<readonly [symbol, ...string[]]>;
|
||||
type R35 = DropLast<readonly string[]>;
|
||||
type R36 = DropLast<readonly []>;
|
||||
|
||||
// Inference to [...T, ...U] with implied arity for T
|
||||
|
||||
function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T) {
|
||||
return (...b: U) => f(...a, ...b);
|
||||
}
|
||||
|
||||
const fn1 = (a: number, b: string, c: boolean, d: string[]) => 0;
|
||||
|
||||
const c0 = curry(fn1); // (a: number, b: string, c: boolean, d: string[]) => number
|
||||
const c1 = curry(fn1, 1); // (b: string, c: boolean, d: string[]) => number
|
||||
const c2 = curry(fn1, 1, 'abc'); // (c: boolean, d: string[]) => number
|
||||
const c3 = curry(fn1, 1, 'abc', true); // (d: string[]) => number
|
||||
const c4 = curry(fn1, 1, 'abc', true, ['x', 'y']); // () => number
|
||||
|
||||
const fn2 = (x: number, b: boolean, ...args: string[]) => 0;
|
||||
|
||||
const c10 = curry(fn2); // (x: number, b: boolean, ...args: string[]) => number
|
||||
const c11 = curry(fn2, 1); // (b: boolean, ...args: string[]) => number
|
||||
const c12 = curry(fn2, 1, true); // (...args: string[]) => number
|
||||
const c13 = curry(fn2, 1, true, 'abc', 'def'); // (...args: string[]) => number
|
||||
|
||||
const fn3 = (...args: string[]) => 0;
|
||||
|
||||
const c20 = curry(fn3); // (...args: string[]) => number
|
||||
const c21 = curry(fn3, 'abc', 'def'); // (...args: string[]) => number
|
||||
const c22 = curry(fn3, ...sa); // (...args: string[]) => number
|
||||
|
||||
// No inference to [...T, ...U] when there is no implied arity
|
||||
|
||||
function curry2<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, t: [...T], u: [...U]) {
|
||||
return f(...t, ...u);
|
||||
}
|
||||
|
||||
declare function fn10(a: string, b: number, c: boolean): string[];
|
||||
|
||||
curry2(fn10, ['hello', 42], [true]);
|
||||
curry2(fn10, ['hello'], [42, true]);
|
||||
|
||||
// Last argument is contextually typed
|
||||
|
||||
declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R];
|
||||
|
||||
call('hello', 32, (a, b) => 42);
|
||||
|
||||
// Would be nice to infer [...string[], (...args: string[]) => number] here
|
||||
// Requires [starting-fixed-part, ...rest-part, ending-fixed-part] tuple structure
|
||||
|
||||
call(...sa, (...x) => 42);
|
||||
~~~~
|
||||
!!! error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
|
||||
|
||||
@@ -0,0 +1,599 @@
|
||||
//// [variadicTuples1.ts]
|
||||
// Variadics in tuple types
|
||||
|
||||
type TV0<T extends unknown[]> = [string, ...T];
|
||||
type TV1<T extends unknown[]> = [string, ...T, number];
|
||||
type TV2<T extends unknown[]> = [string, ...T, number, ...T];
|
||||
type TV3<T extends unknown[]> = [string, ...T, ...number[], ...T]; // Error
|
||||
|
||||
// Normalization
|
||||
|
||||
type TN1 = TV1<[boolean, string]>;
|
||||
type TN2 = TV1<[]>;
|
||||
type TN3 = TV1<[boolean?]>;
|
||||
type TN4 = TV1<string[]>;
|
||||
type TN5 = TV1<[boolean] | [symbol, symbol]>;
|
||||
type TN6 = TV1<any>;
|
||||
type TN7 = TV1<never>;
|
||||
|
||||
// Variadics in array literals
|
||||
|
||||
function tup2<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]) {
|
||||
return [1, ...t, 2, ...u, 3] as const;
|
||||
}
|
||||
|
||||
const t2 = tup2(['hello'], [10, true]);
|
||||
|
||||
function concat<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): [...T, ...U] {
|
||||
return [...t, ...u];
|
||||
}
|
||||
|
||||
declare const sa: string[];
|
||||
|
||||
const tc1 = concat([], []);
|
||||
const tc2 = concat(['hello'], [42]);
|
||||
const tc3 = concat([1, 2, 3], sa);
|
||||
const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
|
||||
|
||||
// Spread arguments
|
||||
|
||||
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
|
||||
|
||||
function foo2(t1: [number, string], t2: [boolean], a1: number[]) {
|
||||
foo1(1, 'abc', true, 42, 43, 44);
|
||||
foo1(...t1, true, 42, 43, 44);
|
||||
foo1(...t1, ...t2, 42, 43, 44);
|
||||
foo1(...t1, ...t2, ...a1);
|
||||
foo1(...t1); // Error
|
||||
foo1(...t1, 45); // Error
|
||||
}
|
||||
|
||||
declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T;
|
||||
|
||||
function foo4<U extends unknown[]>(u: U) {
|
||||
foo3(1, 2);
|
||||
foo3(1, 'hello', true, 2);
|
||||
foo3(1, ...u, 'hi', 2);
|
||||
foo3(1);
|
||||
}
|
||||
|
||||
// Contextual typing of array literals
|
||||
|
||||
declare function ft1<T extends unknown[]>(t: T): T;
|
||||
declare function ft2<T extends unknown[]>(t: T): readonly [...T];
|
||||
declare function ft3<T extends unknown[]>(t: [...T]): T;
|
||||
declare function ft4<T extends unknown[]>(t: [...T]): readonly [...T];
|
||||
|
||||
ft1(['hello', 42]); // (string | number)[]
|
||||
ft2(['hello', 42]); // readonly (string | number)[]
|
||||
ft3(['hello', 42]); // [string, number]
|
||||
ft4(['hello', 42]); // readonly [string, number]
|
||||
|
||||
// Indexing variadic tuple types
|
||||
|
||||
function f0<T extends unknown[]>(t: [string, ...T], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T][1]
|
||||
const c = t[2]; // [string, ...T][2]
|
||||
const d = t[n]; // [string, ...T][number]
|
||||
}
|
||||
|
||||
function f1<T extends unknown[]>(t: [string, ...T, number], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T, number][1]
|
||||
const c = t[2]; // [string, ...T, number][2]
|
||||
const d = t[n]; // [string, ...T, number][number]
|
||||
}
|
||||
|
||||
// Destructuring variadic tuple types
|
||||
|
||||
function f2<T extends unknown[]>(t: [string, ...T]) {
|
||||
let [...ax] = t; // [string, ...T]
|
||||
let [b1, ...bx] = t; // string, [...T]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T][1], T[number][]
|
||||
}
|
||||
|
||||
function f3<T extends unknown[]>(t: [string, ...T, number]) {
|
||||
let [...ax] = t; // [string, ...T, number]
|
||||
let [b1, ...bx] = t; // string, [...T, number]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T, number][1], (number | T[number])[]
|
||||
}
|
||||
|
||||
// Mapped types applied to variadic tuple types
|
||||
|
||||
type Arrayify<T> = { [P in keyof T]: T[P][] };
|
||||
|
||||
type TM1<U extends unknown[]> = Arrayify<readonly [string, number?, ...U, ...boolean[]]>; // [string[], (number | undefined)[]?, Arrayify<U>, ...boolean[][]]
|
||||
|
||||
type TP1<T extends unknown[]> = Partial<[string, ...T, number]>; // [string?, Partial<T>, number?]
|
||||
type TP2<T extends unknown[]> = Partial<[string, ...T, ...number[]]>; // [string?, Partial<T>, ...(number | undefined)[]]
|
||||
|
||||
// Reverse mapping through mapped type applied to variadic tuple type
|
||||
|
||||
declare function fm1<T extends unknown[]>(t: Arrayify<[string, number, ...T]>): T;
|
||||
|
||||
let tm1 = fm1([['abc'], [42], [true], ['def']]); // [boolean, string]
|
||||
|
||||
// Spread of readonly array-like infers mutable array-like
|
||||
|
||||
declare function fx1<T extends unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx1<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx1('abc'); // []
|
||||
fx1('abc', ...u); // U
|
||||
fx1('abc', ...v); // [...V]
|
||||
fx1<U>('abc', ...u); // U
|
||||
fx1<V>('abc', ...v); // Error
|
||||
}
|
||||
|
||||
declare function fx2<T extends readonly unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx2<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx2('abc'); // []
|
||||
fx2('abc', ...u); // U
|
||||
fx2('abc', ...v); // [...V]
|
||||
fx2<U>('abc', ...u); // U
|
||||
fx2<V>('abc', ...v); // V
|
||||
}
|
||||
|
||||
// Relations involving variadic tuple types
|
||||
|
||||
function f10<T extends string[], U extends T>(x: [string, ...unknown[]], y: [string, ...T], z: [string, ...U]) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z;
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
// For a generic type T, [...T] is assignable to T, T is assignable to readonly [...T], and T is assignable
|
||||
// to [...T] when T is constrained to a mutable array or tuple type.
|
||||
|
||||
function f11<T extends unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t;
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t; // Error
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
// Inference between variadic tuple types
|
||||
|
||||
type First<T extends readonly unknown[]> = T[0];
|
||||
type DropFirst<T extends readonly unknown[]> = T extends readonly [any, ...infer U] ? U : [...T];
|
||||
|
||||
type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : undefined;
|
||||
type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any] ? U : [...T];
|
||||
|
||||
type T00 = First<[number, symbol, string]>;
|
||||
type T01 = First<[symbol, string]>;
|
||||
type T02 = First<[string]>;
|
||||
type T03 = First<[number, symbol, ...string[]]>;
|
||||
type T04 = First<[symbol, ...string[]]>;
|
||||
type T05 = First<string[]>;
|
||||
type T06 = First<[]>;
|
||||
type T07 = First<any>;
|
||||
type T08 = First<never>;
|
||||
|
||||
type T10 = DropFirst<[number, symbol, string]>;
|
||||
type T11 = DropFirst<[symbol, string]>;
|
||||
type T12 = DropFirst<[string]>;
|
||||
type T13 = DropFirst<[number, symbol, ...string[]]>;
|
||||
type T14 = DropFirst<[symbol, ...string[]]>;
|
||||
type T15 = DropFirst<string[]>;
|
||||
type T16 = DropFirst<[]>;
|
||||
type T17 = DropFirst<any>;
|
||||
type T18 = DropFirst<never>;
|
||||
|
||||
type T20 = Last<[number, symbol, string]>;
|
||||
type T21 = Last<[symbol, string]>;
|
||||
type T22 = Last<[string]>;
|
||||
type T23 = Last<[number, symbol, ...string[]]>;
|
||||
type T24 = Last<[symbol, ...string[]]>;
|
||||
type T25 = Last<string[]>;
|
||||
type T26 = Last<[]>; // unknown[], maybe should be []
|
||||
type T27 = Last<any>; // unknown, maybe should be any
|
||||
type T28 = Last<never>;
|
||||
|
||||
type T30 = DropLast<[number, symbol, string]>;
|
||||
type T31 = DropLast<[symbol, string]>;
|
||||
type T32 = DropLast<[string]>;
|
||||
type T33 = DropLast<[number, symbol, ...string[]]>;
|
||||
type T34 = DropLast<[symbol, ...string[]]>;
|
||||
type T35 = DropLast<string[]>;
|
||||
type T36 = DropLast<[]>; // unknown[], maybe should be []
|
||||
type T37 = DropLast<any>;
|
||||
type T38 = DropLast<never>;
|
||||
|
||||
type R00 = First<readonly [number, symbol, string]>;
|
||||
type R01 = First<readonly [symbol, string]>;
|
||||
type R02 = First<readonly [string]>;
|
||||
type R03 = First<readonly [number, symbol, ...string[]]>;
|
||||
type R04 = First<readonly [symbol, ...string[]]>;
|
||||
type R05 = First<readonly string[]>;
|
||||
type R06 = First<readonly []>;
|
||||
|
||||
type R10 = DropFirst<readonly [number, symbol, string]>;
|
||||
type R11 = DropFirst<readonly [symbol, string]>;
|
||||
type R12 = DropFirst<readonly [string]>;
|
||||
type R13 = DropFirst<readonly [number, symbol, ...string[]]>;
|
||||
type R14 = DropFirst<readonly [symbol, ...string[]]>;
|
||||
type R15 = DropFirst<readonly string[]>;
|
||||
type R16 = DropFirst<readonly []>;
|
||||
|
||||
type R20 = Last<readonly [number, symbol, string]>;
|
||||
type R21 = Last<readonly [symbol, string]>;
|
||||
type R22 = Last<readonly [string]>;
|
||||
type R23 = Last<readonly [number, symbol, ...string[]]>;
|
||||
type R24 = Last<readonly [symbol, ...string[]]>;
|
||||
type R25 = Last<readonly string[]>;
|
||||
type R26 = Last<readonly []>;
|
||||
|
||||
type R30 = DropLast<readonly [number, symbol, string]>;
|
||||
type R31 = DropLast<readonly [symbol, string]>;
|
||||
type R32 = DropLast<readonly [string]>;
|
||||
type R33 = DropLast<readonly [number, symbol, ...string[]]>;
|
||||
type R34 = DropLast<readonly [symbol, ...string[]]>;
|
||||
type R35 = DropLast<readonly string[]>;
|
||||
type R36 = DropLast<readonly []>;
|
||||
|
||||
// Inference to [...T, ...U] with implied arity for T
|
||||
|
||||
function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T) {
|
||||
return (...b: U) => f(...a, ...b);
|
||||
}
|
||||
|
||||
const fn1 = (a: number, b: string, c: boolean, d: string[]) => 0;
|
||||
|
||||
const c0 = curry(fn1); // (a: number, b: string, c: boolean, d: string[]) => number
|
||||
const c1 = curry(fn1, 1); // (b: string, c: boolean, d: string[]) => number
|
||||
const c2 = curry(fn1, 1, 'abc'); // (c: boolean, d: string[]) => number
|
||||
const c3 = curry(fn1, 1, 'abc', true); // (d: string[]) => number
|
||||
const c4 = curry(fn1, 1, 'abc', true, ['x', 'y']); // () => number
|
||||
|
||||
const fn2 = (x: number, b: boolean, ...args: string[]) => 0;
|
||||
|
||||
const c10 = curry(fn2); // (x: number, b: boolean, ...args: string[]) => number
|
||||
const c11 = curry(fn2, 1); // (b: boolean, ...args: string[]) => number
|
||||
const c12 = curry(fn2, 1, true); // (...args: string[]) => number
|
||||
const c13 = curry(fn2, 1, true, 'abc', 'def'); // (...args: string[]) => number
|
||||
|
||||
const fn3 = (...args: string[]) => 0;
|
||||
|
||||
const c20 = curry(fn3); // (...args: string[]) => number
|
||||
const c21 = curry(fn3, 'abc', 'def'); // (...args: string[]) => number
|
||||
const c22 = curry(fn3, ...sa); // (...args: string[]) => number
|
||||
|
||||
// No inference to [...T, ...U] when there is no implied arity
|
||||
|
||||
function curry2<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, t: [...T], u: [...U]) {
|
||||
return f(...t, ...u);
|
||||
}
|
||||
|
||||
declare function fn10(a: string, b: number, c: boolean): string[];
|
||||
|
||||
curry2(fn10, ['hello', 42], [true]);
|
||||
curry2(fn10, ['hello'], [42, true]);
|
||||
|
||||
// Last argument is contextually typed
|
||||
|
||||
declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R];
|
||||
|
||||
call('hello', 32, (a, b) => 42);
|
||||
|
||||
// Would be nice to infer [...string[], (...args: string[]) => number] here
|
||||
// Requires [starting-fixed-part, ...rest-part, ending-fixed-part] tuple structure
|
||||
|
||||
call(...sa, (...x) => 42);
|
||||
|
||||
|
||||
//// [variadicTuples1.js]
|
||||
"use strict";
|
||||
// Variadics in tuple types
|
||||
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
};
|
||||
// Variadics in array literals
|
||||
function tup2(t, u) {
|
||||
return __spreadArrays([1], t, [2], u, [3]);
|
||||
}
|
||||
var t2 = tup2(['hello'], [10, true]);
|
||||
function concat(t, u) {
|
||||
return __spreadArrays(t, u);
|
||||
}
|
||||
var tc1 = concat([], []);
|
||||
var tc2 = concat(['hello'], [42]);
|
||||
var tc3 = concat([1, 2, 3], sa);
|
||||
var tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
|
||||
function foo2(t1, t2, a1) {
|
||||
foo1(1, 'abc', true, 42, 43, 44);
|
||||
foo1.apply(void 0, __spreadArrays(t1, [true, 42, 43, 44]));
|
||||
foo1.apply(void 0, __spreadArrays(t1, t2, [42, 43, 44]));
|
||||
foo1.apply(void 0, __spreadArrays(t1, t2, a1));
|
||||
foo1.apply(void 0, t1); // Error
|
||||
foo1.apply(void 0, __spreadArrays(t1, [45])); // Error
|
||||
}
|
||||
function foo4(u) {
|
||||
foo3(1, 2);
|
||||
foo3(1, 'hello', true, 2);
|
||||
foo3.apply(void 0, __spreadArrays([1], u, ['hi', 2]));
|
||||
foo3(1);
|
||||
}
|
||||
ft1(['hello', 42]); // (string | number)[]
|
||||
ft2(['hello', 42]); // readonly (string | number)[]
|
||||
ft3(['hello', 42]); // [string, number]
|
||||
ft4(['hello', 42]); // readonly [string, number]
|
||||
// Indexing variadic tuple types
|
||||
function f0(t, n) {
|
||||
var a = t[0]; // string
|
||||
var b = t[1]; // [string, ...T][1]
|
||||
var c = t[2]; // [string, ...T][2]
|
||||
var d = t[n]; // [string, ...T][number]
|
||||
}
|
||||
function f1(t, n) {
|
||||
var a = t[0]; // string
|
||||
var b = t[1]; // [string, ...T, number][1]
|
||||
var c = t[2]; // [string, ...T, number][2]
|
||||
var d = t[n]; // [string, ...T, number][number]
|
||||
}
|
||||
// Destructuring variadic tuple types
|
||||
function f2(t) {
|
||||
var ax = t.slice(0); // [string, ...T]
|
||||
var b1 = t[0], bx = t.slice(1); // string, [...T]
|
||||
var c1 = t[0], c2 = t[1], cx = t.slice(2); // string, [string, ...T][1], T[number][]
|
||||
}
|
||||
function f3(t) {
|
||||
var ax = t.slice(0); // [string, ...T, number]
|
||||
var b1 = t[0], bx = t.slice(1); // string, [...T, number]
|
||||
var c1 = t[0], c2 = t[1], cx = t.slice(2); // string, [string, ...T, number][1], (number | T[number])[]
|
||||
}
|
||||
var tm1 = fm1([['abc'], [42], [true], ['def']]); // [boolean, string]
|
||||
function gx1(u, v) {
|
||||
fx1('abc'); // []
|
||||
fx1.apply(void 0, __spreadArrays(['abc'], u)); // U
|
||||
fx1.apply(void 0, __spreadArrays(['abc'], v)); // [...V]
|
||||
fx1.apply(void 0, __spreadArrays(['abc'], u)); // U
|
||||
fx1.apply(void 0, __spreadArrays(['abc'], v)); // Error
|
||||
}
|
||||
function gx2(u, v) {
|
||||
fx2('abc'); // []
|
||||
fx2.apply(void 0, __spreadArrays(['abc'], u)); // U
|
||||
fx2.apply(void 0, __spreadArrays(['abc'], v)); // [...V]
|
||||
fx2.apply(void 0, __spreadArrays(['abc'], u)); // U
|
||||
fx2.apply(void 0, __spreadArrays(['abc'], v)); // V
|
||||
}
|
||||
// Relations involving variadic tuple types
|
||||
function f10(x, y, z) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z;
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
// For a generic type T, [...T] is assignable to T, T is assignable to readonly [...T], and T is assignable
|
||||
// to [...T] when T is constrained to a mutable array or tuple type.
|
||||
function f11(t, m, r) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t;
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
function f12(t, m, r) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t; // Error
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
// Inference to [...T, ...U] with implied arity for T
|
||||
function curry(f) {
|
||||
var a = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
a[_i - 1] = arguments[_i];
|
||||
}
|
||||
return function () {
|
||||
var b = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
b[_i] = arguments[_i];
|
||||
}
|
||||
return f.apply(void 0, __spreadArrays(a, b));
|
||||
};
|
||||
}
|
||||
var fn1 = function (a, b, c, d) { return 0; };
|
||||
var c0 = curry(fn1); // (a: number, b: string, c: boolean, d: string[]) => number
|
||||
var c1 = curry(fn1, 1); // (b: string, c: boolean, d: string[]) => number
|
||||
var c2 = curry(fn1, 1, 'abc'); // (c: boolean, d: string[]) => number
|
||||
var c3 = curry(fn1, 1, 'abc', true); // (d: string[]) => number
|
||||
var c4 = curry(fn1, 1, 'abc', true, ['x', 'y']); // () => number
|
||||
var fn2 = function (x, b) {
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
var c10 = curry(fn2); // (x: number, b: boolean, ...args: string[]) => number
|
||||
var c11 = curry(fn2, 1); // (b: boolean, ...args: string[]) => number
|
||||
var c12 = curry(fn2, 1, true); // (...args: string[]) => number
|
||||
var c13 = curry(fn2, 1, true, 'abc', 'def'); // (...args: string[]) => number
|
||||
var fn3 = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
var c20 = curry(fn3); // (...args: string[]) => number
|
||||
var c21 = curry(fn3, 'abc', 'def'); // (...args: string[]) => number
|
||||
var c22 = curry.apply(void 0, __spreadArrays([fn3], sa)); // (...args: string[]) => number
|
||||
// No inference to [...T, ...U] when there is no implied arity
|
||||
function curry2(f, t, u) {
|
||||
return f.apply(void 0, __spreadArrays(t, u));
|
||||
}
|
||||
curry2(fn10, ['hello', 42], [true]);
|
||||
curry2(fn10, ['hello'], [42, true]);
|
||||
call('hello', 32, function (a, b) { return 42; });
|
||||
// Would be nice to infer [...string[], (...args: string[]) => number] here
|
||||
// Requires [starting-fixed-part, ...rest-part, ending-fixed-part] tuple structure
|
||||
call.apply(void 0, __spreadArrays(sa, [function () {
|
||||
var x = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
x[_i] = arguments[_i];
|
||||
}
|
||||
return 42;
|
||||
}]));
|
||||
|
||||
|
||||
//// [variadicTuples1.d.ts]
|
||||
declare type TV0<T extends unknown[]> = [string, ...T];
|
||||
declare type TV1<T extends unknown[]> = [string, ...T, number];
|
||||
declare type TV2<T extends unknown[]> = [string, ...T, number, ...T];
|
||||
declare type TV3<T extends unknown[]> = [string, ...T, ...number[], ...T];
|
||||
declare type TN1 = TV1<[boolean, string]>;
|
||||
declare type TN2 = TV1<[]>;
|
||||
declare type TN3 = TV1<[boolean?]>;
|
||||
declare type TN4 = TV1<string[]>;
|
||||
declare type TN5 = TV1<[boolean] | [symbol, symbol]>;
|
||||
declare type TN6 = TV1<any>;
|
||||
declare type TN7 = TV1<never>;
|
||||
declare function tup2<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): readonly [1, ...T, 2, ...U, 3];
|
||||
declare const t2: readonly [1, string, 2, number, boolean, 3];
|
||||
declare function concat<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): [...T, ...U];
|
||||
declare const sa: string[];
|
||||
declare const tc1: [];
|
||||
declare const tc2: [string, number];
|
||||
declare const tc3: [number, number, number, ...string[]];
|
||||
declare const tc4: (string | number)[];
|
||||
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
|
||||
declare function foo2(t1: [number, string], t2: [boolean], a1: number[]): void;
|
||||
declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T;
|
||||
declare function foo4<U extends unknown[]>(u: U): void;
|
||||
declare function ft1<T extends unknown[]>(t: T): T;
|
||||
declare function ft2<T extends unknown[]>(t: T): readonly [...T];
|
||||
declare function ft3<T extends unknown[]>(t: [...T]): T;
|
||||
declare function ft4<T extends unknown[]>(t: [...T]): readonly [...T];
|
||||
declare function f0<T extends unknown[]>(t: [string, ...T], n: number): void;
|
||||
declare function f1<T extends unknown[]>(t: [string, ...T, number], n: number): void;
|
||||
declare function f2<T extends unknown[]>(t: [string, ...T]): void;
|
||||
declare function f3<T extends unknown[]>(t: [string, ...T, number]): void;
|
||||
declare type Arrayify<T> = {
|
||||
[P in keyof T]: T[P][];
|
||||
};
|
||||
declare type TM1<U extends unknown[]> = Arrayify<readonly [string, number?, ...U, ...boolean[]]>;
|
||||
declare type TP1<T extends unknown[]> = Partial<[string, ...T, number]>;
|
||||
declare type TP2<T extends unknown[]> = Partial<[string, ...T, ...number[]]>;
|
||||
declare function fm1<T extends unknown[]>(t: Arrayify<[string, number, ...T]>): T;
|
||||
declare let tm1: [boolean, string];
|
||||
declare function fx1<T extends unknown[]>(a: string, ...args: T): T;
|
||||
declare function gx1<U extends unknown[], V extends readonly unknown[]>(u: U, v: V): void;
|
||||
declare function fx2<T extends readonly unknown[]>(a: string, ...args: T): T;
|
||||
declare function gx2<U extends unknown[], V extends readonly unknown[]>(u: U, v: V): void;
|
||||
declare function f10<T extends string[], U extends T>(x: [string, ...unknown[]], y: [string, ...T], z: [string, ...U]): void;
|
||||
declare function f11<T extends unknown[]>(t: T, m: [...T], r: readonly [...T]): void;
|
||||
declare function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly [...T]): void;
|
||||
declare type First<T extends readonly unknown[]> = T[0];
|
||||
declare type DropFirst<T extends readonly unknown[]> = T extends readonly [any, ...infer U] ? U : [...T];
|
||||
declare type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : undefined;
|
||||
declare type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any] ? U : [...T];
|
||||
declare type T00 = First<[number, symbol, string]>;
|
||||
declare type T01 = First<[symbol, string]>;
|
||||
declare type T02 = First<[string]>;
|
||||
declare type T03 = First<[number, symbol, ...string[]]>;
|
||||
declare type T04 = First<[symbol, ...string[]]>;
|
||||
declare type T05 = First<string[]>;
|
||||
declare type T06 = First<[]>;
|
||||
declare type T07 = First<any>;
|
||||
declare type T08 = First<never>;
|
||||
declare type T10 = DropFirst<[number, symbol, string]>;
|
||||
declare type T11 = DropFirst<[symbol, string]>;
|
||||
declare type T12 = DropFirst<[string]>;
|
||||
declare type T13 = DropFirst<[number, symbol, ...string[]]>;
|
||||
declare type T14 = DropFirst<[symbol, ...string[]]>;
|
||||
declare type T15 = DropFirst<string[]>;
|
||||
declare type T16 = DropFirst<[]>;
|
||||
declare type T17 = DropFirst<any>;
|
||||
declare type T18 = DropFirst<never>;
|
||||
declare type T20 = Last<[number, symbol, string]>;
|
||||
declare type T21 = Last<[symbol, string]>;
|
||||
declare type T22 = Last<[string]>;
|
||||
declare type T23 = Last<[number, symbol, ...string[]]>;
|
||||
declare type T24 = Last<[symbol, ...string[]]>;
|
||||
declare type T25 = Last<string[]>;
|
||||
declare type T26 = Last<[]>;
|
||||
declare type T27 = Last<any>;
|
||||
declare type T28 = Last<never>;
|
||||
declare type T30 = DropLast<[number, symbol, string]>;
|
||||
declare type T31 = DropLast<[symbol, string]>;
|
||||
declare type T32 = DropLast<[string]>;
|
||||
declare type T33 = DropLast<[number, symbol, ...string[]]>;
|
||||
declare type T34 = DropLast<[symbol, ...string[]]>;
|
||||
declare type T35 = DropLast<string[]>;
|
||||
declare type T36 = DropLast<[]>;
|
||||
declare type T37 = DropLast<any>;
|
||||
declare type T38 = DropLast<never>;
|
||||
declare type R00 = First<readonly [number, symbol, string]>;
|
||||
declare type R01 = First<readonly [symbol, string]>;
|
||||
declare type R02 = First<readonly [string]>;
|
||||
declare type R03 = First<readonly [number, symbol, ...string[]]>;
|
||||
declare type R04 = First<readonly [symbol, ...string[]]>;
|
||||
declare type R05 = First<readonly string[]>;
|
||||
declare type R06 = First<readonly []>;
|
||||
declare type R10 = DropFirst<readonly [number, symbol, string]>;
|
||||
declare type R11 = DropFirst<readonly [symbol, string]>;
|
||||
declare type R12 = DropFirst<readonly [string]>;
|
||||
declare type R13 = DropFirst<readonly [number, symbol, ...string[]]>;
|
||||
declare type R14 = DropFirst<readonly [symbol, ...string[]]>;
|
||||
declare type R15 = DropFirst<readonly string[]>;
|
||||
declare type R16 = DropFirst<readonly []>;
|
||||
declare type R20 = Last<readonly [number, symbol, string]>;
|
||||
declare type R21 = Last<readonly [symbol, string]>;
|
||||
declare type R22 = Last<readonly [string]>;
|
||||
declare type R23 = Last<readonly [number, symbol, ...string[]]>;
|
||||
declare type R24 = Last<readonly [symbol, ...string[]]>;
|
||||
declare type R25 = Last<readonly string[]>;
|
||||
declare type R26 = Last<readonly []>;
|
||||
declare type R30 = DropLast<readonly [number, symbol, string]>;
|
||||
declare type R31 = DropLast<readonly [symbol, string]>;
|
||||
declare type R32 = DropLast<readonly [string]>;
|
||||
declare type R33 = DropLast<readonly [number, symbol, ...string[]]>;
|
||||
declare type R34 = DropLast<readonly [symbol, ...string[]]>;
|
||||
declare type R35 = DropLast<readonly string[]>;
|
||||
declare type R36 = DropLast<readonly []>;
|
||||
declare function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T): (...b: U) => R;
|
||||
declare const fn1: (a: number, b: string, c: boolean, d: string[]) => number;
|
||||
declare const c0: (a: number, b: string, c: boolean, d: string[]) => number;
|
||||
declare const c1: (b: string, c: boolean, d: string[]) => number;
|
||||
declare const c2: (c: boolean, d: string[]) => number;
|
||||
declare const c3: (d: string[]) => number;
|
||||
declare const c4: () => number;
|
||||
declare const fn2: (x: number, b: boolean, ...args: string[]) => number;
|
||||
declare const c10: (x: number, b: boolean, ...args: string[]) => number;
|
||||
declare const c11: (b: boolean, ...args: string[]) => number;
|
||||
declare const c12: (...b: string[]) => number;
|
||||
declare const c13: (...b: string[]) => number;
|
||||
declare const fn3: (...args: string[]) => number;
|
||||
declare const c20: (...b: string[]) => number;
|
||||
declare const c21: (...b: string[]) => number;
|
||||
declare const c22: (...b: string[]) => number;
|
||||
declare function curry2<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, t: [...T], u: [...U]): R;
|
||||
declare function fn10(a: string, b: number, c: boolean): string[];
|
||||
declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R];
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,6 @@
|
||||
tests/cases/conformance/types/tuple/wideningTuples3.ts(3,5): error TS7005: Variable 'b' implicitly has an '[any, any]' type.
|
||||
tests/cases/conformance/types/tuple/wideningTuples3.ts(3,9): error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '2' is not assignable to type '1'.
|
||||
Source has 2 element(s) but target allows only 1.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/wideningTuples3.ts (2 errors) ====
|
||||
@@ -12,5 +11,4 @@ tests/cases/conformance/types/tuple/wideningTuples3.ts(3,9): error TS2322: Type
|
||||
!!! error TS7005: Variable 'b' implicitly has an '[any, any]' type.
|
||||
~
|
||||
!!! error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '2' is not assignable to type '1'.
|
||||
!!! error TS2322: Source has 2 element(s) but target allows only 1.
|
||||
@@ -1,6 +1,5 @@
|
||||
tests/cases/conformance/types/tuple/wideningTuples4.ts(3,9): error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
|
||||
Types of property 'length' are incompatible.
|
||||
Type '2' is not assignable to type '1'.
|
||||
Source has 2 element(s) but target allows only 1.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/wideningTuples4.ts (1 errors) ====
|
||||
@@ -9,6 +8,5 @@ tests/cases/conformance/types/tuple/wideningTuples4.ts(3,9): error TS2322: Type
|
||||
var b = a = [undefined, null];
|
||||
~
|
||||
!!! error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
|
||||
!!! error TS2322: Types of property 'length' are incompatible.
|
||||
!!! error TS2322: Type '2' is not assignable to type '1'.
|
||||
!!! error TS2322: Source has 2 element(s) but target allows only 1.
|
||||
b = ["", ""];
|
||||
@@ -0,0 +1,300 @@
|
||||
// @strict: true
|
||||
// @declaration: true
|
||||
|
||||
// Variadics in tuple types
|
||||
|
||||
type TV0<T extends unknown[]> = [string, ...T];
|
||||
type TV1<T extends unknown[]> = [string, ...T, number];
|
||||
type TV2<T extends unknown[]> = [string, ...T, number, ...T];
|
||||
type TV3<T extends unknown[]> = [string, ...T, ...number[], ...T]; // Error
|
||||
|
||||
// Normalization
|
||||
|
||||
type TN1 = TV1<[boolean, string]>;
|
||||
type TN2 = TV1<[]>;
|
||||
type TN3 = TV1<[boolean?]>;
|
||||
type TN4 = TV1<string[]>;
|
||||
type TN5 = TV1<[boolean] | [symbol, symbol]>;
|
||||
type TN6 = TV1<any>;
|
||||
type TN7 = TV1<never>;
|
||||
|
||||
// Variadics in array literals
|
||||
|
||||
function tup2<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]) {
|
||||
return [1, ...t, 2, ...u, 3] as const;
|
||||
}
|
||||
|
||||
const t2 = tup2(['hello'], [10, true]);
|
||||
|
||||
function concat<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): [...T, ...U] {
|
||||
return [...t, ...u];
|
||||
}
|
||||
|
||||
declare const sa: string[];
|
||||
|
||||
const tc1 = concat([], []);
|
||||
const tc2 = concat(['hello'], [42]);
|
||||
const tc3 = concat([1, 2, 3], sa);
|
||||
const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
|
||||
|
||||
// Spread arguments
|
||||
|
||||
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
|
||||
|
||||
function foo2(t1: [number, string], t2: [boolean], a1: number[]) {
|
||||
foo1(1, 'abc', true, 42, 43, 44);
|
||||
foo1(...t1, true, 42, 43, 44);
|
||||
foo1(...t1, ...t2, 42, 43, 44);
|
||||
foo1(...t1, ...t2, ...a1);
|
||||
foo1(...t1); // Error
|
||||
foo1(...t1, 45); // Error
|
||||
}
|
||||
|
||||
declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T;
|
||||
|
||||
function foo4<U extends unknown[]>(u: U) {
|
||||
foo3(1, 2);
|
||||
foo3(1, 'hello', true, 2);
|
||||
foo3(1, ...u, 'hi', 2);
|
||||
foo3(1);
|
||||
}
|
||||
|
||||
// Contextual typing of array literals
|
||||
|
||||
declare function ft1<T extends unknown[]>(t: T): T;
|
||||
declare function ft2<T extends unknown[]>(t: T): readonly [...T];
|
||||
declare function ft3<T extends unknown[]>(t: [...T]): T;
|
||||
declare function ft4<T extends unknown[]>(t: [...T]): readonly [...T];
|
||||
|
||||
ft1(['hello', 42]); // (string | number)[]
|
||||
ft2(['hello', 42]); // readonly (string | number)[]
|
||||
ft3(['hello', 42]); // [string, number]
|
||||
ft4(['hello', 42]); // readonly [string, number]
|
||||
|
||||
// Indexing variadic tuple types
|
||||
|
||||
function f0<T extends unknown[]>(t: [string, ...T], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T][1]
|
||||
const c = t[2]; // [string, ...T][2]
|
||||
const d = t[n]; // [string, ...T][number]
|
||||
}
|
||||
|
||||
function f1<T extends unknown[]>(t: [string, ...T, number], n: number) {
|
||||
const a = t[0]; // string
|
||||
const b = t[1]; // [string, ...T, number][1]
|
||||
const c = t[2]; // [string, ...T, number][2]
|
||||
const d = t[n]; // [string, ...T, number][number]
|
||||
}
|
||||
|
||||
// Destructuring variadic tuple types
|
||||
|
||||
function f2<T extends unknown[]>(t: [string, ...T]) {
|
||||
let [...ax] = t; // [string, ...T]
|
||||
let [b1, ...bx] = t; // string, [...T]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T][1], T[number][]
|
||||
}
|
||||
|
||||
function f3<T extends unknown[]>(t: [string, ...T, number]) {
|
||||
let [...ax] = t; // [string, ...T, number]
|
||||
let [b1, ...bx] = t; // string, [...T, number]
|
||||
let [c1, c2, ...cx] = t; // string, [string, ...T, number][1], (number | T[number])[]
|
||||
}
|
||||
|
||||
// Mapped types applied to variadic tuple types
|
||||
|
||||
type Arrayify<T> = { [P in keyof T]: T[P][] };
|
||||
|
||||
type TM1<U extends unknown[]> = Arrayify<readonly [string, number?, ...U, ...boolean[]]>; // [string[], (number | undefined)[]?, Arrayify<U>, ...boolean[][]]
|
||||
|
||||
type TP1<T extends unknown[]> = Partial<[string, ...T, number]>; // [string?, Partial<T>, number?]
|
||||
type TP2<T extends unknown[]> = Partial<[string, ...T, ...number[]]>; // [string?, Partial<T>, ...(number | undefined)[]]
|
||||
|
||||
// Reverse mapping through mapped type applied to variadic tuple type
|
||||
|
||||
declare function fm1<T extends unknown[]>(t: Arrayify<[string, number, ...T]>): T;
|
||||
|
||||
let tm1 = fm1([['abc'], [42], [true], ['def']]); // [boolean, string]
|
||||
|
||||
// Spread of readonly array-like infers mutable array-like
|
||||
|
||||
declare function fx1<T extends unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx1<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx1('abc'); // []
|
||||
fx1('abc', ...u); // U
|
||||
fx1('abc', ...v); // [...V]
|
||||
fx1<U>('abc', ...u); // U
|
||||
fx1<V>('abc', ...v); // Error
|
||||
}
|
||||
|
||||
declare function fx2<T extends readonly unknown[]>(a: string, ...args: T): T;
|
||||
|
||||
function gx2<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) {
|
||||
fx2('abc'); // []
|
||||
fx2('abc', ...u); // U
|
||||
fx2('abc', ...v); // [...V]
|
||||
fx2<U>('abc', ...u); // U
|
||||
fx2<V>('abc', ...v); // V
|
||||
}
|
||||
|
||||
// Relations involving variadic tuple types
|
||||
|
||||
function f10<T extends string[], U extends T>(x: [string, ...unknown[]], y: [string, ...T], z: [string, ...U]) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z;
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
// For a generic type T, [...T] is assignable to T, T is assignable to readonly [...T], and T is assignable
|
||||
// to [...T] when T is constrained to a mutable array or tuple type.
|
||||
|
||||
function f11<T extends unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t;
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly [...T]) {
|
||||
t = m;
|
||||
t = r; // Error
|
||||
m = t; // Error
|
||||
m = r; // Error
|
||||
r = t;
|
||||
r = m;
|
||||
}
|
||||
|
||||
// Inference between variadic tuple types
|
||||
|
||||
type First<T extends readonly unknown[]> = T[0];
|
||||
type DropFirst<T extends readonly unknown[]> = T extends readonly [any, ...infer U] ? U : [...T];
|
||||
|
||||
type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : undefined;
|
||||
type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any] ? U : [...T];
|
||||
|
||||
type T00 = First<[number, symbol, string]>;
|
||||
type T01 = First<[symbol, string]>;
|
||||
type T02 = First<[string]>;
|
||||
type T03 = First<[number, symbol, ...string[]]>;
|
||||
type T04 = First<[symbol, ...string[]]>;
|
||||
type T05 = First<string[]>;
|
||||
type T06 = First<[]>;
|
||||
type T07 = First<any>;
|
||||
type T08 = First<never>;
|
||||
|
||||
type T10 = DropFirst<[number, symbol, string]>;
|
||||
type T11 = DropFirst<[symbol, string]>;
|
||||
type T12 = DropFirst<[string]>;
|
||||
type T13 = DropFirst<[number, symbol, ...string[]]>;
|
||||
type T14 = DropFirst<[symbol, ...string[]]>;
|
||||
type T15 = DropFirst<string[]>;
|
||||
type T16 = DropFirst<[]>;
|
||||
type T17 = DropFirst<any>;
|
||||
type T18 = DropFirst<never>;
|
||||
|
||||
type T20 = Last<[number, symbol, string]>;
|
||||
type T21 = Last<[symbol, string]>;
|
||||
type T22 = Last<[string]>;
|
||||
type T23 = Last<[number, symbol, ...string[]]>;
|
||||
type T24 = Last<[symbol, ...string[]]>;
|
||||
type T25 = Last<string[]>;
|
||||
type T26 = Last<[]>; // unknown[], maybe should be []
|
||||
type T27 = Last<any>; // unknown, maybe should be any
|
||||
type T28 = Last<never>;
|
||||
|
||||
type T30 = DropLast<[number, symbol, string]>;
|
||||
type T31 = DropLast<[symbol, string]>;
|
||||
type T32 = DropLast<[string]>;
|
||||
type T33 = DropLast<[number, symbol, ...string[]]>;
|
||||
type T34 = DropLast<[symbol, ...string[]]>;
|
||||
type T35 = DropLast<string[]>;
|
||||
type T36 = DropLast<[]>; // unknown[], maybe should be []
|
||||
type T37 = DropLast<any>;
|
||||
type T38 = DropLast<never>;
|
||||
|
||||
type R00 = First<readonly [number, symbol, string]>;
|
||||
type R01 = First<readonly [symbol, string]>;
|
||||
type R02 = First<readonly [string]>;
|
||||
type R03 = First<readonly [number, symbol, ...string[]]>;
|
||||
type R04 = First<readonly [symbol, ...string[]]>;
|
||||
type R05 = First<readonly string[]>;
|
||||
type R06 = First<readonly []>;
|
||||
|
||||
type R10 = DropFirst<readonly [number, symbol, string]>;
|
||||
type R11 = DropFirst<readonly [symbol, string]>;
|
||||
type R12 = DropFirst<readonly [string]>;
|
||||
type R13 = DropFirst<readonly [number, symbol, ...string[]]>;
|
||||
type R14 = DropFirst<readonly [symbol, ...string[]]>;
|
||||
type R15 = DropFirst<readonly string[]>;
|
||||
type R16 = DropFirst<readonly []>;
|
||||
|
||||
type R20 = Last<readonly [number, symbol, string]>;
|
||||
type R21 = Last<readonly [symbol, string]>;
|
||||
type R22 = Last<readonly [string]>;
|
||||
type R23 = Last<readonly [number, symbol, ...string[]]>;
|
||||
type R24 = Last<readonly [symbol, ...string[]]>;
|
||||
type R25 = Last<readonly string[]>;
|
||||
type R26 = Last<readonly []>;
|
||||
|
||||
type R30 = DropLast<readonly [number, symbol, string]>;
|
||||
type R31 = DropLast<readonly [symbol, string]>;
|
||||
type R32 = DropLast<readonly [string]>;
|
||||
type R33 = DropLast<readonly [number, symbol, ...string[]]>;
|
||||
type R34 = DropLast<readonly [symbol, ...string[]]>;
|
||||
type R35 = DropLast<readonly string[]>;
|
||||
type R36 = DropLast<readonly []>;
|
||||
|
||||
// Inference to [...T, ...U] with implied arity for T
|
||||
|
||||
function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T) {
|
||||
return (...b: U) => f(...a, ...b);
|
||||
}
|
||||
|
||||
const fn1 = (a: number, b: string, c: boolean, d: string[]) => 0;
|
||||
|
||||
const c0 = curry(fn1); // (a: number, b: string, c: boolean, d: string[]) => number
|
||||
const c1 = curry(fn1, 1); // (b: string, c: boolean, d: string[]) => number
|
||||
const c2 = curry(fn1, 1, 'abc'); // (c: boolean, d: string[]) => number
|
||||
const c3 = curry(fn1, 1, 'abc', true); // (d: string[]) => number
|
||||
const c4 = curry(fn1, 1, 'abc', true, ['x', 'y']); // () => number
|
||||
|
||||
const fn2 = (x: number, b: boolean, ...args: string[]) => 0;
|
||||
|
||||
const c10 = curry(fn2); // (x: number, b: boolean, ...args: string[]) => number
|
||||
const c11 = curry(fn2, 1); // (b: boolean, ...args: string[]) => number
|
||||
const c12 = curry(fn2, 1, true); // (...args: string[]) => number
|
||||
const c13 = curry(fn2, 1, true, 'abc', 'def'); // (...args: string[]) => number
|
||||
|
||||
const fn3 = (...args: string[]) => 0;
|
||||
|
||||
const c20 = curry(fn3); // (...args: string[]) => number
|
||||
const c21 = curry(fn3, 'abc', 'def'); // (...args: string[]) => number
|
||||
const c22 = curry(fn3, ...sa); // (...args: string[]) => number
|
||||
|
||||
// No inference to [...T, ...U] when there is no implied arity
|
||||
|
||||
function curry2<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, t: [...T], u: [...U]) {
|
||||
return f(...t, ...u);
|
||||
}
|
||||
|
||||
declare function fn10(a: string, b: number, c: boolean): string[];
|
||||
|
||||
curry2(fn10, ['hello', 42], [true]);
|
||||
curry2(fn10, ['hello'], [42, true]);
|
||||
|
||||
// Last argument is contextually typed
|
||||
|
||||
declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R];
|
||||
|
||||
call('hello', 32, (a, b) => 42);
|
||||
|
||||
// Would be nice to infer [...string[], (...args: string[]) => number] here
|
||||
// Requires [starting-fixed-part, ...rest-part, ending-fixed-part] tuple structure
|
||||
|
||||
call(...sa, (...x) => 42);
|
||||
Reference in new issue
Block a user