File: spreadObjectOrFalsy.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (60 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download | duplicates (3)
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
tests/cases/conformance/types/spread/spreadObjectOrFalsy.ts(2,14): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/types/spread/spreadObjectOrFalsy.ts(10,14): error TS2698: Spread types may only be created from object types.


==== tests/cases/conformance/types/spread/spreadObjectOrFalsy.ts (2 errors) ====
    function f1<T>(a: T & undefined) {
        return { ...a };  // Error
                 ~~~~
!!! error TS2698: Spread types may only be created from object types.
    }
    
    function f2<T>(a: T | T & undefined) {
        return { ...a };
    }
    
    function f3<T extends undefined>(a: T) {
        return { ...a };  // Error
                 ~~~~
!!! error TS2698: Spread types may only be created from object types.
    }
    
    function f4<T extends undefined>(a: object | T) {
        return { ...a };
    }
    
    function f5<S, T extends undefined>(a: S | T) {
        return { ...a };
    }
    
    function f6<T extends object | undefined>(a: T) {
        return { ...a };
    }
    
    // Repro from #46976
    
    function g1<T extends {}, A extends { z: (T | undefined) & T }>(a: A) {
        const { z } = a;
        return {
            ...z
        };
    }
    
    // Repro from #47028
    
    interface DatafulFoo<T> {
        data: T;
    }
    
    class Foo<T extends string> {
        data: T | undefined;
        bar() {
            if (this.hasData()) {
                this.data.toLocaleLowerCase();
            }
        }
        hasData(): this is DatafulFoo<T> {
            return true;
        }
    }