-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow implicit return with explicit undefined
return type
#53092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3bee8eb
17b43e5
b267f96
e38cd2d
03c6cb5
ec64119
1eed970
168fa04
5632662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(1,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(99,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(104,16): error TS2378: A 'get' accessor must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(126,15): error TS18050: The value 'undefined' cannot be used here. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(127,5): error TS1003: Identifier expected. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(1,16): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(99,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(107,17): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(112,16): error TS2378: A 'get' accessor must return a value. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(134,15): error TS18050: The value 'undefined' cannot be used here. | ||
tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(135,5): error TS1003: Identifier expected. | ||
|
||
|
||
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (5 errors) ==== | ||
==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (6 errors) ==== | ||
function f1(): string { | ||
~~~~~~ | ||
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. | ||
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
// errors because there are no return statements | ||
} | ||
|
||
|
@@ -40,12 +41,12 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(127,5): e | |
return null; | ||
} | ||
|
||
function f8(): void { | ||
function f8(): any { | ||
// Fine since are typed any. | ||
return; | ||
} | ||
|
||
function f9(): void { | ||
function f9(): any { | ||
// Fine since we are typed any and return undefined | ||
return undefined; | ||
} | ||
|
@@ -108,10 +109,20 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(127,5): e | |
|
||
function f21(): number | string { | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. | ||
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
// Not okay; union does not contain void or any | ||
} | ||
|
||
function f22(): undefined { | ||
// Okay; return type allows implicit return of undefined | ||
} | ||
|
||
function f23(): undefined | number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your last commit only included this baseline, as f23 doesn't appear to be anywhere else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tapped the commit button from GitHub, will add it with the another change for the feedback. |
||
~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value. | ||
// Error; because `undefined | number` becomes `number` without strictNullChecks. | ||
} | ||
|
||
class C { | ||
public get m1() { | ||
~~ | ||
|
@@ -143,4 +154,5 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(127,5): e | |
} | ||
~ | ||
!!! error TS1003: Identifier expected. | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//// [functionsMissingReturnStatementsAndExpressions2.ts] | ||
function f1(): undefined | number { | ||
// Okay; return type allows implicit return of undefined | ||
} | ||
|
||
|
||
//// [functionsMissingReturnStatementsAndExpressions2.js] | ||
function f1() { | ||
// Okay; return type allows implicit return of undefined | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions2.ts === | ||
function f1(): undefined | number { | ||
>f1 : Symbol(f1, Decl(functionsMissingReturnStatementsAndExpressions2.ts, 0, 0)) | ||
|
||
// Okay; return type allows implicit return of undefined | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions2.ts === | ||
function f1(): undefined | number { | ||
>f1 : () => undefined | number | ||
|
||
// Okay; return type allows implicit return of undefined | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @allowUnreachableCode: true | ||
// @strictNullChecks: true | ||
|
||
// @target: es5 | ||
|
||
function f1(): undefined | number { | ||
// Okay; return type allows implicit return of undefined | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(To match the comments, as otherwise these two are exactly same with f5 and f6.)