File: arrayLiteralExpressionContextualTyping.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (38 lines) | stat: -rw-r--r-- 3,082 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(6,5): error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
  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]'.
  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]'.
  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]'.
  Source has 6 element(s) but target allows only 3.


==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (4 errors) ====
    // In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by
    //      the type of the property with the numeric name N in the contextual type, if any, or otherwise
    //      the numeric index type of the contextual type, if any.
    var array = [1, 2, 3];
    var array1 = [true, 2, 3];  // Contextual type by the numeric index type of the contextual type
    var tup: [number, number, number] = [1, 2, 3, 4];
        ~~~
!!! error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
!!! 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:   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:   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.
    var spr = [1, 2, 3, ...array];
    var spr1 = [1, 2, 3, ...tup];
    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:   Source has 6 element(s) but target allows only 3.