File: spreadInvalidArgumentType.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (93 lines) | stat: -rw-r--r-- 4,527 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
tests/cases/compiler/spreadInvalidArgumentType.ts(33,16): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(34,16): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(39,16): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(42,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(44,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(45,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(47,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(48,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(52,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(53,17): error TS2698: Spread types may only be created from object types.
tests/cases/compiler/spreadInvalidArgumentType.ts(55,17): error TS2698: Spread types may only be created from object types.


==== tests/cases/compiler/spreadInvalidArgumentType.ts (11 errors) ====
    enum E { v1, v2 };
    
    function f<T extends { b: string }>(p1: T, p2: T[]) {
        var t: T;
    
        var i: T["b"];
        var k: keyof T;
    
        var mapped_generic: {[P in keyof T]: T[P]};
        var mapped: {[P in "b"]: T[P]};
    
        var union_generic: T | { a: number };
        var union_primitive: { a: number } | number;
    
        var intersection_generic: T & { a: number };
        var intersection_primitive: { a: number } | string;
    
        var num: number;
        var str: number;
        var literal_string: "string";
        var literal_number: 42;
    
        var u: undefined;
        var n: null;
        var a: any;
    
    
        var e: E;
    
        var o1 = { ...p1 };  // OK, generic type paramterre
        var o2 = { ...p2 };  // OK
        var o3 = { ...t };   // OK, generic type paramter
        var o4 = { ...i };   // Error, index access
                   ~~~~
!!! error TS2698: Spread types may only be created from object types.
        var o5 = { ...k };   // Error, index
                   ~~~~
!!! error TS2698: Spread types may only be created from object types.
        var o6 = { ...mapped_generic }; // OK, generic mapped object type
        var o7 = { ...mapped };  // OK, non-generic mapped type
    
        var o8 = { ...union_generic };  // OK, union with generic type parameter
        var o9 = { ...union_primitive };  // Error, union with generic type parameter
                   ~~~~~~~~~~~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
    
        var o10 = { ...intersection_generic };  // OK, intersection with generic type parameter
        var o11 = { ...intersection_primitive };  // Error, intersection with generic type parameter
                    ~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
    
        var o12 = { ...num };  // Error
                    ~~~~~~
!!! error TS2698: Spread types may only be created from object types.
        var o13 = { ...str };  // Error
                    ~~~~~~
!!! error TS2698: Spread types may only be created from object types.
    
        var o14 = { ...u };  // error, undefined-only not allowed
                    ~~~~
!!! error TS2698: Spread types may only be created from object types.
        var o15 = { ...n };  // error, null-only not allowed
                    ~~~~
!!! error TS2698: Spread types may only be created from object types.
    
        var o16 = { ...a };  // OK
    
        var o17 = { ...literal_string };  // Error
                    ~~~~~~~~~~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
        var o18 = { ...literal_number };  // Error
                    ~~~~~~~~~~~~~~~~~
!!! error TS2698: Spread types may only be created from object types.
    
        var o19 = { ...e };  // Error, enum
                    ~~~~
!!! error TS2698: Spread types may only be created from object types.
    }