Skip to content

Commit 7d54015

Browse files
committed
Add more tests
1 parent 37b1048 commit 7d54015

File tree

4 files changed

+391
-0
lines changed

4 files changed

+391
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
tests/cases/compiler/noImplicitReturnsExclusions.ts(16,26): error TS7030: Not all code paths return a value.
2+
tests/cases/compiler/noImplicitReturnsExclusions.ts(24,26): error TS7030: Not all code paths return a value.
3+
tests/cases/compiler/noImplicitReturnsExclusions.ts(40,10): error TS7030: Not all code paths return a value.
4+
tests/cases/compiler/noImplicitReturnsExclusions.ts(44,10): error TS7030: Not all code paths return a value.
5+
tests/cases/compiler/noImplicitReturnsExclusions.ts(48,10): error TS7030: Not all code paths return a value.
6+
tests/cases/compiler/noImplicitReturnsExclusions.ts(53,10): error TS7030: Not all code paths return a value.
7+
8+
9+
==== tests/cases/compiler/noImplicitReturnsExclusions.ts (6 errors) ====
10+
// Functions with a return type of any, undefined, or a type that includes void are excluded
11+
// from --noImplicitReturns checks.
12+
13+
function f1(b: boolean): undefined {
14+
if (b) return undefined;
15+
}
16+
17+
function f2(b: boolean): void {
18+
if (b) return undefined;
19+
}
20+
21+
function f3(b: boolean): any {
22+
if (b) return undefined;
23+
}
24+
25+
function f4(b: boolean): string | undefined { // Error
26+
~~~~~~~~~~~~~~~~~~
27+
!!! error TS7030: Not all code paths return a value.
28+
if (b) return undefined;
29+
}
30+
31+
function f5(b: boolean): string | void {
32+
if (b) return undefined;
33+
}
34+
35+
function f6(b: boolean): unknown { // Error
36+
~~~~~~~
37+
!!! error TS7030: Not all code paths return a value.
38+
if (b) return undefined;
39+
}
40+
41+
function f10(b: boolean) {
42+
if (b) return;
43+
}
44+
45+
function f11(b: boolean) {
46+
if (b) return undefined;
47+
}
48+
49+
function f12(b: boolean) {
50+
if (b) return undefined as any;
51+
}
52+
53+
function f13(b: boolean) { // Error
54+
~~~
55+
!!! error TS7030: Not all code paths return a value.
56+
if (b) return undefined as unknown;
57+
}
58+
59+
function f14(b: boolean) { // Error
60+
~~~
61+
!!! error TS7030: Not all code paths return a value.
62+
if (b) return 42;
63+
}
64+
65+
function f15(b: boolean) { // Error
66+
~~~
67+
!!! error TS7030: Not all code paths return a value.
68+
if (b) return 42;
69+
if (b) return undefined;
70+
}
71+
72+
function f16(b: boolean) { // Error
73+
~~~
74+
!!! error TS7030: Not all code paths return a value.
75+
if (b) return 42;
76+
if (b) return;
77+
}
78+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
=== tests/cases/compiler/noImplicitReturnsExclusions.ts ===
2+
// Functions with a return type of any, undefined, or a type that includes void are excluded
3+
// from --noImplicitReturns checks.
4+
5+
function f1(b: boolean): undefined {
6+
>f1 : Symbol(f1, Decl(noImplicitReturnsExclusions.ts, 0, 0))
7+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 3, 12))
8+
9+
if (b) return undefined;
10+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 3, 12))
11+
>undefined : Symbol(undefined)
12+
}
13+
14+
function f2(b: boolean): void {
15+
>f2 : Symbol(f2, Decl(noImplicitReturnsExclusions.ts, 5, 1))
16+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 7, 12))
17+
18+
if (b) return undefined;
19+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 7, 12))
20+
>undefined : Symbol(undefined)
21+
}
22+
23+
function f3(b: boolean): any {
24+
>f3 : Symbol(f3, Decl(noImplicitReturnsExclusions.ts, 9, 1))
25+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 11, 12))
26+
27+
if (b) return undefined;
28+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 11, 12))
29+
>undefined : Symbol(undefined)
30+
}
31+
32+
function f4(b: boolean): string | undefined { // Error
33+
>f4 : Symbol(f4, Decl(noImplicitReturnsExclusions.ts, 13, 1))
34+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 15, 12))
35+
36+
if (b) return undefined;
37+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 15, 12))
38+
>undefined : Symbol(undefined)
39+
}
40+
41+
function f5(b: boolean): string | void {
42+
>f5 : Symbol(f5, Decl(noImplicitReturnsExclusions.ts, 17, 1))
43+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 19, 12))
44+
45+
if (b) return undefined;
46+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 19, 12))
47+
>undefined : Symbol(undefined)
48+
}
49+
50+
function f6(b: boolean): unknown { // Error
51+
>f6 : Symbol(f6, Decl(noImplicitReturnsExclusions.ts, 21, 1))
52+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 23, 12))
53+
54+
if (b) return undefined;
55+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 23, 12))
56+
>undefined : Symbol(undefined)
57+
}
58+
59+
function f10(b: boolean) {
60+
>f10 : Symbol(f10, Decl(noImplicitReturnsExclusions.ts, 25, 1))
61+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 27, 13))
62+
63+
if (b) return;
64+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 27, 13))
65+
}
66+
67+
function f11(b: boolean) {
68+
>f11 : Symbol(f11, Decl(noImplicitReturnsExclusions.ts, 29, 1))
69+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 31, 13))
70+
71+
if (b) return undefined;
72+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 31, 13))
73+
>undefined : Symbol(undefined)
74+
}
75+
76+
function f12(b: boolean) {
77+
>f12 : Symbol(f12, Decl(noImplicitReturnsExclusions.ts, 33, 1))
78+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 35, 13))
79+
80+
if (b) return undefined as any;
81+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 35, 13))
82+
>undefined : Symbol(undefined)
83+
}
84+
85+
function f13(b: boolean) { // Error
86+
>f13 : Symbol(f13, Decl(noImplicitReturnsExclusions.ts, 37, 1))
87+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 39, 13))
88+
89+
if (b) return undefined as unknown;
90+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 39, 13))
91+
>undefined : Symbol(undefined)
92+
}
93+
94+
function f14(b: boolean) { // Error
95+
>f14 : Symbol(f14, Decl(noImplicitReturnsExclusions.ts, 41, 1))
96+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 43, 13))
97+
98+
if (b) return 42;
99+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 43, 13))
100+
}
101+
102+
function f15(b: boolean) { // Error
103+
>f15 : Symbol(f15, Decl(noImplicitReturnsExclusions.ts, 45, 1))
104+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 47, 13))
105+
106+
if (b) return 42;
107+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 47, 13))
108+
109+
if (b) return undefined;
110+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 47, 13))
111+
>undefined : Symbol(undefined)
112+
}
113+
114+
function f16(b: boolean) { // Error
115+
>f16 : Symbol(f16, Decl(noImplicitReturnsExclusions.ts, 50, 1))
116+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 52, 13))
117+
118+
if (b) return 42;
119+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 52, 13))
120+
121+
if (b) return;
122+
>b : Symbol(b, Decl(noImplicitReturnsExclusions.ts, 52, 13))
123+
}
124+
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
=== tests/cases/compiler/noImplicitReturnsExclusions.ts ===
2+
// Functions with a return type of any, undefined, or a type that includes void are excluded
3+
// from --noImplicitReturns checks.
4+
5+
function f1(b: boolean): undefined {
6+
>f1 : (b: boolean) => undefined
7+
>b : boolean
8+
9+
if (b) return undefined;
10+
>b : boolean
11+
>undefined : undefined
12+
}
13+
14+
function f2(b: boolean): void {
15+
>f2 : (b: boolean) => void
16+
>b : boolean
17+
18+
if (b) return undefined;
19+
>b : boolean
20+
>undefined : undefined
21+
}
22+
23+
function f3(b: boolean): any {
24+
>f3 : (b: boolean) => any
25+
>b : boolean
26+
27+
if (b) return undefined;
28+
>b : boolean
29+
>undefined : undefined
30+
}
31+
32+
function f4(b: boolean): string | undefined { // Error
33+
>f4 : (b: boolean) => string | undefined
34+
>b : boolean
35+
36+
if (b) return undefined;
37+
>b : boolean
38+
>undefined : undefined
39+
}
40+
41+
function f5(b: boolean): string | void {
42+
>f5 : (b: boolean) => string | void
43+
>b : boolean
44+
45+
if (b) return undefined;
46+
>b : boolean
47+
>undefined : undefined
48+
}
49+
50+
function f6(b: boolean): unknown { // Error
51+
>f6 : (b: boolean) => unknown
52+
>b : boolean
53+
54+
if (b) return undefined;
55+
>b : boolean
56+
>undefined : undefined
57+
}
58+
59+
function f10(b: boolean) {
60+
>f10 : (b: boolean) => void
61+
>b : boolean
62+
63+
if (b) return;
64+
>b : boolean
65+
}
66+
67+
function f11(b: boolean) {
68+
>f11 : (b: boolean) => undefined
69+
>b : boolean
70+
71+
if (b) return undefined;
72+
>b : boolean
73+
>undefined : undefined
74+
}
75+
76+
function f12(b: boolean) {
77+
>f12 : (b: boolean) => any
78+
>b : boolean
79+
80+
if (b) return undefined as any;
81+
>b : boolean
82+
>undefined as any : any
83+
>undefined : undefined
84+
}
85+
86+
function f13(b: boolean) { // Error
87+
>f13 : (b: boolean) => unknown
88+
>b : boolean
89+
90+
if (b) return undefined as unknown;
91+
>b : boolean
92+
>undefined as unknown : unknown
93+
>undefined : undefined
94+
}
95+
96+
function f14(b: boolean) { // Error
97+
>f14 : (b: boolean) => 42 | undefined
98+
>b : boolean
99+
100+
if (b) return 42;
101+
>b : boolean
102+
>42 : 42
103+
}
104+
105+
function f15(b: boolean) { // Error
106+
>f15 : (b: boolean) => 42 | undefined
107+
>b : boolean
108+
109+
if (b) return 42;
110+
>b : boolean
111+
>42 : 42
112+
113+
if (b) return undefined;
114+
>b : false
115+
>undefined : undefined
116+
}
117+
118+
function f16(b: boolean) { // Error
119+
>f16 : (b: boolean) => 42 | undefined
120+
>b : boolean
121+
122+
if (b) return 42;
123+
>b : boolean
124+
>42 : 42
125+
126+
if (b) return;
127+
>b : false
128+
}
129+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// @strict: true
2+
// @noImplicitReturns: true
3+
// @noEmit: true
4+
5+
// Functions with a return type of any, undefined, or a type that includes void are excluded
6+
// from --noImplicitReturns checks.
7+
8+
function f1(b: boolean): undefined {
9+
if (b) return undefined;
10+
}
11+
12+
function f2(b: boolean): void {
13+
if (b) return undefined;
14+
}
15+
16+
function f3(b: boolean): any {
17+
if (b) return undefined;
18+
}
19+
20+
function f4(b: boolean): string | undefined { // Error
21+
if (b) return undefined;
22+
}
23+
24+
function f5(b: boolean): string | void {
25+
if (b) return undefined;
26+
}
27+
28+
function f6(b: boolean): unknown { // Error
29+
if (b) return undefined;
30+
}
31+
32+
function f10(b: boolean) {
33+
if (b) return;
34+
}
35+
36+
function f11(b: boolean) {
37+
if (b) return undefined;
38+
}
39+
40+
function f12(b: boolean) {
41+
if (b) return undefined as any;
42+
}
43+
44+
function f13(b: boolean) { // Error
45+
if (b) return undefined as unknown;
46+
}
47+
48+
function f14(b: boolean) { // Error
49+
if (b) return 42;
50+
}
51+
52+
function f15(b: boolean) { // Error
53+
if (b) return 42;
54+
if (b) return undefined;
55+
}
56+
57+
function f16(b: boolean) { // Error
58+
if (b) return 42;
59+
if (b) return;
60+
}

0 commit comments

Comments
 (0)