File: genericCallWithObjectTypeArgsAndInitializers.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 (28 lines) | stat: -rw-r--r-- 2,435 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
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts(5,33): error TS2322: Type 'number' is not assignable to type 'T'.
  'number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts(6,37): error TS2322: Type 'T' is not assignable to type 'U'.
  'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts(8,56): error TS2322: Type 'U' is not assignable to type 'V'.
  'V' could be instantiated with an arbitrary type which could be unrelated to 'U'.


==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts (3 errors) ====
    // Generic typed parameters with initializers
    
    function foo<T>(x: T = null) { return x; } // ok
    function foo2<T>(x: T = undefined) { return x; } // ok
    function foo3<T extends Number>(x: T = 1) { } // error
                                    ~~~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'T'.
!!! error TS2322:   'number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Number'.
    function foo4<T, U extends T>(x: T, y: U = x) { } // error
                                        ~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322:   'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
!!! related TS2208 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts:6:15: This type parameter might need an `extends U` constraint.
    function foo5<T, U extends T>(x: U, y: T = x) { } // ok
    function foo6<T, U extends T, V extends U>(x: T, y: U, z: V = y) { } // error
                                                           ~~~~~~~~
!!! error TS2322: Type 'U' is not assignable to type 'V'.
!!! error TS2322:   'V' could be instantiated with an arbitrary type which could be unrelated to 'U'.
    function foo7<T, U extends T, V extends U>(x: V, y: U = x) { } // should be ok