Skip to content

throw in arrow functions forces a void return type #7538

Closed
@srijs

Description

@srijs

TypeScript Version:

1.8

Code

// compiles
function foo(): number {
    throw new Error('Everything is gonna be alright!');
}

// does not compile
const bar: () => number = () => {
    throw new Error('WHYUNO?!?');
}

Expected behavior:
Functions foo and bar type-check, because an exception is thrown in their body which effectively means "bottom", so any return type should be permitted.

Actual behavior:
While function foo type-checks, bar does not.

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions