Skip to content

Commit 54d35b9

Browse files
committed
Add tests
1 parent ed4dc57 commit 54d35b9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
// Suppress strict property initialization check
5+
6+
class C1 {
7+
a!: number;
8+
b: string; // Error
9+
}
10+
11+
// Suppress definite assignment check in constructor
12+
13+
class C2 {
14+
a!: number;
15+
constructor() {
16+
let x = this.a;
17+
}
18+
}
19+
20+
// Definite assignment assertion requires type annotation, no initializer, no static modifier
21+
22+
class C3 {
23+
a! = 1;
24+
b!: number = 1;
25+
static c!: number;
26+
}
27+
28+
// Definite assignment assertion not permitted in ambient context
29+
30+
declare class C4 {
31+
a!: number;
32+
}
33+
34+
// Definite assignment assertion not permitted on abstract property
35+
36+
abstract class C5 {
37+
abstract a!: number;
38+
}
39+
40+
// Suppress definite assignment check for variable
41+
42+
function f1() {
43+
let x!: number;
44+
let y = x;
45+
var a!: number;
46+
var b = a;
47+
}
48+
49+
function f2() {
50+
let x!: string | number;
51+
if (typeof x === "string") {
52+
let s: string = x;
53+
}
54+
else {
55+
let n: number = x;
56+
}
57+
}
58+
59+
function f3() {
60+
let x!: number;
61+
const g = () => {
62+
x = 1;
63+
}
64+
g();
65+
let y = x;
66+
}
67+
68+
// Definite assignment assertion requires type annotation and no initializer
69+
70+
function f4() {
71+
let a!;
72+
let b! = 1;
73+
let c!: number = 1;
74+
}
75+
76+
// Definite assignment assertion not permitted in ambient context
77+
78+
declare let v1!: number;
79+
declare var v2!: number;

0 commit comments

Comments
 (0)