File: genericCallWithObjectTypeArgsAndInitializers.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (45 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (5)
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
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/genericCallWithObjectTypeArgsAndInitializers.ts ===
// Generic typed parameters with initializers

function foo<T>(x: T = null) { return x; } // ok
>foo : <T>(x?: T) => T
>x : T
>null : null
>x : T

function foo2<T>(x: T = undefined) { return x; } // ok
>foo2 : <T>(x?: T) => T
>x : T
>undefined : undefined
>x : T

function foo3<T extends Number>(x: T = 1) { } // error
>foo3 : <T extends Number>(x?: T) => void
>x : T
>1 : 1

function foo4<T, U extends T>(x: T, y: U = x) { } // error
>foo4 : <T, U extends T>(x: T, y?: U) => void
>x : T
>y : U
>x : T

function foo5<T, U extends T>(x: U, y: T = x) { } // ok
>foo5 : <T, U extends T>(x: U, y?: T) => void
>x : U
>y : T
>x : U

function foo6<T, U extends T, V extends U>(x: T, y: U, z: V = y) { } // error
>foo6 : <T, U extends T, V extends U>(x: T, y: U, z?: V) => void
>x : T
>y : U
>z : V
>y : U

function foo7<T, U extends T, V extends U>(x: V, y: U = x) { } // should be ok
>foo7 : <T, U extends T, V extends U>(x: V, y?: U) => void
>x : V
>y : U
>x : V