Skip to content

Feature Request: Process of Elimination for Unions #4893

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

Closed
Gaelan opened this issue Sep 21, 2015 · 2 comments
Closed

Feature Request: Process of Elimination for Unions #4893

Gaelan opened this issue Sep 21, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Gaelan
Copy link

Gaelan commented Sep 21, 2015

This should compile without errors:

declare function getDBObjectById(id: number): DBObject;
declare function bar(arg: DBObject): void;
function foo(arg: number | DBObject) {
  if (arg instanceof DBObject) {
    bar(arg)
  } else {
    bar(getDBObjectById(arg) // error TS2345: Argument of type 'number | DBObject' is not assignable to parameter of type 'number'.
                             // Type 'DBObject' is not assignable to type 'number'.
  }
}
@mhegazy
Copy link
Contributor

mhegazy commented Sep 21, 2015

looks like a duplicate of #1719

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 21, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 21, 2015

also note that typeof arg !== "number" will work as you expect.

@mhegazy mhegazy closed this as completed Sep 21, 2015
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants