Skip to content

Commit b54de54

Browse files
committed
Add regression tests
1 parent b1a4cb4 commit b54de54

4 files changed

+215
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [contextuallyTypedBooleanLiterals.ts]
2+
// Repro from #48363
3+
4+
type Box<T> = {
5+
get: () => T,
6+
set: (value: T) => void
7+
}
8+
9+
declare function box<T>(value: T): Box<T>;
10+
11+
const bn1 = box(0); // Box<number>
12+
const bn2: Box<number> = box(0); // Ok
13+
14+
const bb1 = box(false); // Box<boolean>
15+
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean>
16+
17+
// Repro from #48150
18+
19+
interface Observable<T>
20+
{
21+
(): T;
22+
(value: T): any;
23+
}
24+
25+
declare function observable<T>(value: T): Observable<T>;
26+
27+
const x: Observable<boolean> = observable(false);
28+
29+
30+
//// [contextuallyTypedBooleanLiterals.js]
31+
"use strict";
32+
// Repro from #48363
33+
var bn1 = box(0); // Box<number>
34+
var bn2 = box(0); // Ok
35+
var bb1 = box(false); // Box<boolean>
36+
var bb2 = box(false); // Error, box<false> not assignable to Box<boolean>
37+
var x = observable(false);
38+
39+
40+
//// [contextuallyTypedBooleanLiterals.d.ts]
41+
declare type Box<T> = {
42+
get: () => T;
43+
set: (value: T) => void;
44+
};
45+
declare function box<T>(value: T): Box<T>;
46+
declare const bn1: Box<number>;
47+
declare const bn2: Box<number>;
48+
declare const bb1: Box<boolean>;
49+
declare const bb2: Box<boolean>;
50+
interface Observable<T> {
51+
(): T;
52+
(value: T): any;
53+
}
54+
declare function observable<T>(value: T): Observable<T>;
55+
declare const x: Observable<boolean>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
=== tests/cases/compiler/contextuallyTypedBooleanLiterals.ts ===
2+
// Repro from #48363
3+
4+
type Box<T> = {
5+
>Box : Box<T>
6+
7+
get: () => T,
8+
>get : () => T
9+
10+
set: (value: T) => void
11+
>set : (value: T) => void
12+
>value : T
13+
}
14+
15+
declare function box<T>(value: T): Box<T>;
16+
>box : <T>(value: T) => Box<T>
17+
>value : T
18+
19+
const bn1 = box(0); // Box<number>
20+
>bn1 : Box<number>
21+
>box(0) : Box<number>
22+
>box : <T>(value: T) => Box<T>
23+
>0 : 0
24+
25+
const bn2: Box<number> = box(0); // Ok
26+
>bn2 : Box<number>
27+
>box(0) : Box<number>
28+
>box : <T>(value: T) => Box<T>
29+
>0 : 0
30+
31+
const bb1 = box(false); // Box<boolean>
32+
>bb1 : Box<boolean>
33+
>box(false) : Box<boolean>
34+
>box : <T>(value: T) => Box<T>
35+
>false : false
36+
37+
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean>
38+
>bb2 : Box<boolean>
39+
>box(false) : Box<boolean>
40+
>box : <T>(value: T) => Box<T>
41+
>false : false
42+
43+
// Repro from #48150
44+
45+
interface Observable<T>
46+
{
47+
(): T;
48+
(value: T): any;
49+
>value : T
50+
}
51+
52+
declare function observable<T>(value: T): Observable<T>;
53+
>observable : <T>(value: T) => Observable<T>
54+
>value : T
55+
56+
const x: Observable<boolean> = observable(false);
57+
>x : Observable<boolean>
58+
>observable(false) : Observable<boolean>
59+
>observable : <T>(value: T) => Observable<T>
60+
>false : false
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
// Repro from #48363
5+
6+
type Box<T> = {
7+
get: () => T,
8+
set: (value: T) => void
9+
}
10+
11+
declare function box<T>(value: T): Box<T>;
12+
13+
const bn1 = box(0); // Box<number>
14+
const bn2: Box<number> = box(0); // Ok
15+
16+
const bb1 = box(false); // Box<boolean>
17+
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean>
18+
19+
// Repro from #48150
20+
21+
interface Observable<T>
22+
{
23+
(): T;
24+
(value: T): any;
25+
}
26+
27+
declare function observable<T>(value: T): Observable<T>;
28+
29+
const x: Observable<boolean> = observable(false);

0 commit comments

Comments
 (0)