|
| 1 | +=== tests/cases/compiler/contextuallyTypedBooleanLiterals.ts === |
| 2 | +// Repro from #48363 |
| 3 | + |
| 4 | +type Box<T> = { |
| 5 | +>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) |
| 6 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) |
| 7 | + |
| 8 | + get: () => T, |
| 9 | +>get : Symbol(get, Decl(contextuallyTypedBooleanLiterals.ts, 2, 15)) |
| 10 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) |
| 11 | + |
| 12 | + set: (value: T) => void |
| 13 | +>set : Symbol(set, Decl(contextuallyTypedBooleanLiterals.ts, 3, 17)) |
| 14 | +>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 4, 10)) |
| 15 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) |
| 16 | +} |
| 17 | + |
| 18 | +declare function box<T>(value: T): Box<T>; |
| 19 | +>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) |
| 20 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) |
| 21 | +>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 7, 24)) |
| 22 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) |
| 23 | +>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) |
| 24 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) |
| 25 | + |
| 26 | +const bn1 = box(0); // Box<number> |
| 27 | +>bn1 : Symbol(bn1, Decl(contextuallyTypedBooleanLiterals.ts, 9, 5)) |
| 28 | +>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) |
| 29 | + |
| 30 | +const bn2: Box<number> = box(0); // Ok |
| 31 | +>bn2 : Symbol(bn2, Decl(contextuallyTypedBooleanLiterals.ts, 10, 5)) |
| 32 | +>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) |
| 33 | +>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) |
| 34 | + |
| 35 | +const bb1 = box(false); // Box<boolean> |
| 36 | +>bb1 : Symbol(bb1, Decl(contextuallyTypedBooleanLiterals.ts, 12, 5)) |
| 37 | +>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) |
| 38 | + |
| 39 | +const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean> |
| 40 | +>bb2 : Symbol(bb2, Decl(contextuallyTypedBooleanLiterals.ts, 13, 5)) |
| 41 | +>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) |
| 42 | +>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) |
| 43 | + |
| 44 | +// Repro from #48150 |
| 45 | + |
| 46 | +interface Observable<T> |
| 47 | +>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) |
| 48 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) |
| 49 | +{ |
| 50 | + (): T; |
| 51 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) |
| 52 | + |
| 53 | + (value: T): any; |
| 54 | +>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 20, 3)) |
| 55 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) |
| 56 | +} |
| 57 | + |
| 58 | +declare function observable<T>(value: T): Observable<T>; |
| 59 | +>observable : Symbol(observable, Decl(contextuallyTypedBooleanLiterals.ts, 21, 1)) |
| 60 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) |
| 61 | +>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 23, 31)) |
| 62 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) |
| 63 | +>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) |
| 64 | +>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) |
| 65 | + |
| 66 | +const x: Observable<boolean> = observable(false); |
| 67 | +>x : Symbol(x, Decl(contextuallyTypedBooleanLiterals.ts, 25, 5)) |
| 68 | +>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) |
| 69 | +>observable : Symbol(observable, Decl(contextuallyTypedBooleanLiterals.ts, 21, 1)) |
| 70 | + |
0 commit comments