* 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
40 lines
3.1 KiB
Plaintext
40 lines
3.1 KiB
Plaintext
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]'.
|
|
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]'.
|
|
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 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) ====
|
|
// In a typed function call, argument expressions are contextually typed by their corresponding parameter types.
|
|
function foo({x: [a, b], y: {c, d, e}}) { }
|
|
function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { }
|
|
function baz(x: [string, number, boolean]) { }
|
|
|
|
var o = { x: ["string", 1], y: { c: true, d: "world", e: 3 } };
|
|
var o1: { x: [string, number], y: { c: boolean, d: string, e: number } } = { x: ["string", 1], y: { c: true, d: "world", e: 3 } };
|
|
foo(o1); // Not error since x has contextual type of tuple namely [string, number]
|
|
foo({ x: ["string", 1], y: { c: true, d: "world", e: 3 } }); // Not error
|
|
|
|
var array = ["string", 1, true];
|
|
var tuple: [string, number, boolean] = ["string", 1, true];
|
|
baz(tuple);
|
|
baz(["string", 1, true]);
|
|
|
|
baz(array); // Error
|
|
~~~~~
|
|
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
|
|
!!! 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: 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 not assignable to type '[any, any]'.
|
|
!!! error TS2345: Target requires 2 element(s) but source may have fewer. |