Skip to content
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

Non-void functions can omit return expressions #162

Closed
DanielRosenwasser opened this issue Jul 20, 2014 · 1 comment
Closed

Non-void functions can omit return expressions #162

DanielRosenwasser opened this issue Jul 20, 2014 · 1 comment
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

The old compiler was permissive with both of the following code snippets:

function foo(): number {
    return;
}
class C {
    public foo() {
        return;
    }
}

as per the 1.0 spec (6.3):

An explicitly typed function whose return type isn't the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single throw statement.

I believe we should change this to

An explicitly typed function whose return type isn't the Void or the Any type must have at least one return expression somewhere in its body. An exception to this rule is if the function implementation consists of a single throw statement.

It seems weird that we allow implicit return of undefined through return statements with no explicit expression, but we don't allow the implicit return of undefined through by omitting return statements entirely.

@DanielRosenwasser DanielRosenwasser changed the title Functions with annotated return types, and get accessors, can lack a return expressions Functions with annotated return types, and get accessors, can omit return expressions Jul 20, 2014
@DanielRosenwasser DanielRosenwasser changed the title Functions with annotated return types, and get accessors, can omit return expressions Non-void functions can omit return expressions Jul 22, 2014
@RyanCavanaugh
Copy link
Member

Forward-duping to #228

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants