8000 Non-void functions can omit return expressions · Issue #162 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Non-void functions can omit return expressions #162
@DanielRosenwasser

Description

@DanielRosenwasser

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0