32 lines
No EOL
2 KiB
Text
32 lines
No EOL
2 KiB
Text
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts (11 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
|
|
~~~~~~~~
|
|
!!! Type 'number' is not assignable to type 'T'.
|
|
function foo4<T, U extends T>(x: T, y: U = x) { } // error
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~
|
|
!!! Type 'T' is not assignable to type 'U'.
|
|
function foo5<T, U extends T>(x: U, y: T = x) { } // ok
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~
|
|
!!! Type 'U' is not assignable to type 'T'.
|
|
function foo6<T, U extends T, V extends U>(x: T, y: U, z: V = y) { } // error
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~
|
|
!!! Type 'U' is not assignable to type 'V'.
|
|
function foo7<T, U extends T, V extends U>(x: V, y: U = x) { } // should be ok
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~
|
|
!!! Type 'V' is not assignable to type 'U'. |