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

Only infer 'never' in function expressions and arrow functions #8767

Merged
merged 4 commits into from
May 23, 2016

Conversation

ahejlsberg
Copy link
Member

This PR modifies the type inference rules such that we only infer a function result of never in function expressions and arrow functions. For regular functions and methods, in cases where we would have inferred never we now instead infer void. This matches the behavior we had before the introduction of never and ensures better backwards compatibility. For example:

class Base {
    overrideMe() {
        throw new Error("You forgot to override me!");
    }
}

class Derived {
    overrideMe() {
        // Code that actually returns here
    }
}

The above pattern is reasonably common and was broken because a never returning method cannot be overridden by a void returning method.

This PR only affects return type inference. It has no impact on functions and methods that explicitly specify a return type.

@mhegazy
Copy link
Contributor

mhegazy commented May 23, 2016

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants