Skip to content

Commit 0dc485a

Browse files
committed
Added test case
1 parent 4673b57 commit 0dc485a

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(3,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
2-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(95,16): error TS2378: A 'get' accessor must return a value.
3-
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(118,5): error TS1003: Identifier expected.
2+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(93,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
3+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(101,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
4+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(106,16): error TS2378: A 'get' accessor must return a value.
5+
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(129,5): error TS1003: Identifier expected.
46

57

6-
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (3 errors) ====
8+
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (5 errors) ====
79

810

911
function f1(): string {
@@ -98,6 +100,21 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(118,5): e
98100
return "Okay, not type annotated.";
99101
}
100102

103+
function f19(): void | number {
104+
~~~~~~~~~~~~~
105+
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
106+
// Okay; function return type is union containing void
107+
}
108+
109+
function f20(): any | number {
110+
// Okay; function return type is union containing any
111+
}
112+
113+
function f21(): number | string {
114+
~~~~~~~~~~~~~~~
115+
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
116+
// Not okay; union does not contain void or any
117+
}
101118

102119
class C {
103120
public get m1() {

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ function f18() {
9191
return "Okay, not type annotated.";
9292
}
9393

94+
function f19(): void | number {
95+
// Okay; function return type is union containing void
96+
}
97+
98+
function f20(): any | number {
99+
// Okay; function return type is union containing any
100+
}
101+
102+
function f21(): number | string {
103+
// Not okay; union does not contain void or any
104+
}
94105

95106
class C {
96107
public get m1() {
@@ -191,6 +202,15 @@ function f17() {
191202
function f18() {
192203
return "Okay, not type annotated.";
193204
}
205+
function f19() {
206+
// Okay; function return type is union containing void
207+
}
208+
function f20() {
209+
// Okay; function return type is union containing any
210+
}
211+
function f21() {
212+
// Not okay; union does not contain void or any
213+
}
194214
var C = (function () {
195215
function C() {
196216
}

tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ function f18() {
9292
return "Okay, not type annotated.";
9393
}
9494

95+
function f19(): void | number {
96+
// Okay; function return type is union containing void
97+
}
98+
99+
function f20(): any | number {
100+
// Okay; function return type is union containing any
101+
}
102+
103+
function f21(): number | string {
104+
// Not okay; union does not contain void or any
105+
}
95106

96107
class C {
97108
public get m1() {

0 commit comments

Comments
 (0)