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

Display 'nothing' for the empty union type #8340

Merged
merged 2 commits into from
Apr 27, 2016
Merged

Display 'nothing' for the empty union type #8340

merged 2 commits into from
Apr 27, 2016

Conversation

ahejlsberg
Copy link
Member

With this PR we display the name 'nothing' for empty union types. Empty union types can occur when control flow type analysis concludes that there is no possible type for a variable that matches the preceding type guards in a particular code path. For example:

function foo(x: string | number) {
    if (typeof x === "string") {
        x;  // x is of type string here
    }
    else if (typeof x === "number") {
        x;  // x is of type number here
    }
    else {
        x;  // x is of type nothing here
    }
}

The 'nothing' type cannot be explicitly named, it has no members, and no other types are compatible with it.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2016

👍

@ahejlsberg ahejlsberg merged commit 0613ad1 into master Apr 27, 2016
@ahejlsberg ahejlsberg mentioned this pull request May 17, 2016
@mhegazy mhegazy deleted the nothingType branch November 2, 2017 21:05
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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