Skip to content

Non-void functions can omit return expressions #162

Description

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

functionfoo(): number{return;}
classC{publicfoo(){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 returnexpression 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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