File: typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.types

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 (49 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (4)
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
=== tests/cases/compiler/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts ===
// tricky interface
interface Settable<T, V> {
    set(value: V): T;
>set : (value: V) => T
>value : V
}

// implement
class Identity<V> implements Settable<Identity<V>, V> {
>Identity : Identity<V>

    readonly item: V;
>item : V

    constructor(value: V) {
>value : V

        this.item = value;
>this.item = value : V
>this.item : V
>this : this
>item : V
>value : V
    }
    public set(value: V): Identity<V> {
>set : (value: V) => Identity<V>
>value : V

        return new Identity<V>(value);
>new Identity<V>(value) : Identity<V>
>Identity : typeof Identity
>value : V
    }
}

// generic parameter default
interface Test1<V, T extends Settable<T, V> = Identity<V>> { };
let test1: Test1<number>;
>test1 : Test1<number, Identity<number>>

// not generic parameter default
interface Test2Base<V, T extends Settable<T, V>> { };
type Test2<V> = Test2Base<V, Identity<V>>;
>Test2 : Test2<V>

let test2: Test2<number>;
>test2 : Test2<number>