forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert-nonnull.ts
53 lines (41 loc) · 1.04 KB
/
assert-nonnull.ts
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
export function testVar(n: Error | null): Error {
return n!;
}
class Foo {
bar: Foo | null;
baz: (() => Foo | null) | null;
}
export function testObj(foo: Foo | null): Foo | null {
return foo!.bar;
}
export function testProp(foo: Foo): Foo {
return foo.bar!;
}
export function testArr(foo: Array<Foo> | null): Foo {
return foo![0];
}
export function testElem(foo: Array<Foo | null>): Foo {
return foo[0]!;
}
export function testAll(foo: Array<Foo | null> | null): Foo {
return foo![0]!.bar!;
}
export function testAll2(foo: Array<Foo | null> | null): Foo {
return foo!![0]!!.bar!!; // 3x AS225: Expression is never 'null'
}
export function testFn(fn: (() => Foo | null) | null): Foo | null {
return fn!();
}
export function testFn2(fn: (() => Foo | null) | null): Foo | null {
let fn2 = fn!;
return fn2();
}
export function testRet(fn: (() => Foo | null) | null): Foo {
return fn!()!;
}
export function testObjFn(foo: Foo): Foo | null {
return foo.baz!();
}
export function testObjRet(foo: Foo): Foo {
return foo.baz!()!;
}