FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Display 'nothing' for the empty union type by ahejlsberg · Pull Request #8340 · microsoft/TypeScript · GitHub

Display 'nothing' for the empty union type - #8340

Merged
Anders Hejlsberg (ahejlsberg) merged 2 commits into
masterfrom
nothingType
Apr 27, 2016
Merged

Display 'nothing' for the empty union type#8340
Anders Hejlsberg (ahejlsberg) merged 2 commits into
masterfrom
nothingType

Conversation

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

👍

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL