File: contextuallyTypedBooleanLiterals.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 (61 lines) | stat: -rw-r--r-- 1,304 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
=== tests/cases/compiler/contextuallyTypedBooleanLiterals.ts ===
// Repro from #48363

type Box<T> = {
>Box : Box<T>

    get: () => T,
>get : () => T

    set: (value: T) => void
>set : (value: T) => void
>value : T
}

declare function box<T>(value: T): Box<T>;
>box : <T>(value: T) => Box<T>
>value : T

const bn1 = box(0);  // Box<number>
>bn1 : Box<number>
>box(0) : Box<number>
>box : <T>(value: T) => Box<T>
>0 : 0

const bn2: Box<number> = box(0);  // Ok
>bn2 : Box<number>
>box(0) : Box<number>
>box : <T>(value: T) => Box<T>
>0 : 0

const bb1 = box(false);  // Box<boolean>
>bb1 : Box<boolean>
>box(false) : Box<boolean>
>box : <T>(value: T) => Box<T>
>false : false

const bb2: Box<boolean> = box(false);  // Error, box<false> not assignable to Box<boolean>
>bb2 : Box<boolean>
>box(false) : Box<boolean>
>box : <T>(value: T) => Box<T>
>false : false

// Repro from #48150

interface Observable<T>
{
  (): T;
  (value: T): any;
>value : T
}

declare function observable<T>(value: T): Observable<T>;
>observable : <T>(value: T) => Observable<T>
>value : T

const x: Observable<boolean> = observable(false);
>x : Observable<boolean>
>observable(false) : Observable<boolean>
>observable : <T>(value: T) => Observable<T>
>false : false