File: nonPrimitiveInGeneric.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 (72 lines) | stat: -rw-r--r-- 3,287 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
61
62
63
64
65
66
67
68
69
70
71
72
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(2,9): error TS2322: Type 'T' is not assignable to type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(9,17): error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(10,17): error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(18,7): error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(19,7): error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(25,8): error TS2344: Type 'number' does not satisfy the constraint 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(26,8): error TS2344: Type 'string' does not satisfy the constraint 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(34,14): error TS2344: Type 'number' does not satisfy the constraint 'object'.


==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts (8 errors) ====
    function generic<T>(t: T) {
        var o: object = t; // expect error
            ~
!!! error TS2322: Type 'T' is not assignable to type 'object'.
!!! related TS2208 tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts:1:18: This type parameter might need an `extends object` constraint.
    }
    var a = {};
    var b = "42";
    
    generic<object>({});
    generic<object>(a);
    generic<object>(123); // expect error
                    ~~~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
    generic<object>(b); // expect error
                    ~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
    
    function bound<T extends object>(t: T) {
        var o: object = t; // ok
    }
    
    bound({});
    bound(a);
    bound(123); // expect error
          ~~~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'object'.
    bound(b); // expect error
          ~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
    
    function bound2<T extends object>() {}
    
    bound2<{}>();
    bound2<Object>();
    bound2<number>(); // expect error
           ~~~~~~
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
    bound2<string>(); // expect error
           ~~~~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'object'.
    
    function bound3<T extends {}>(t: T) {
        var o: object = t; // ok
    }
    
    interface Proxy<T extends object> {}
    
    var x: Proxy<number>; // error
                 ~~~~~~
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
    var y: Proxy<null>; // ok
    var z: Proxy<undefined> ; // ok
    
    
    interface Blah {
        foo: number;
    }
    
    var u: Proxy<Blah>; // ok