Skip to content

Go-to-definition on tagged union property should filter down to known union case #25774

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
RikkiGibson opened this issue Jul 18, 2018 · 2 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@RikkiGibson
Copy link
Member

RikkiGibson commented Jul 18, 2018

TypeScript Version: 2.9.1
Issue produced using vscode 1.25.1 which appears to depend on 2.9.1

Search Terms:
tagged union, go to definition

Code

type Animal = Cat | Dog;

interface Cat {
  animaltype: "Cat",
  color: string,
  friendly: boolean;
};

interface Dog {
  animaltype: "Dog",
  color: string,
  likesToFetch: boolean;
}

const cat: Animal = {
  animaltype: "Cat",
  color: "brown",
  friendly: true
};

Expected behavior:
Go-to-definition on the color property goes to the definition on Cat instead of showing definitions for both Cat and Dog.

Actual behavior:
Go-to-definition shows candidate definitions in both the Cat and Dog interfaces.

Playground Link: https://www.typescriptlang.org/play/#src=type%20Animal%20%3D%20Cat%20%7C%20Dog%3B%0D%0A%0D%0Ainterface%20Cat%20%7B%0D%0A%20%20animaltype%3A%20%22Cat%22%2C%0D%0A%20%20color%3A%20string%2C%0D%0A%20%20friendly%3A%20boolean%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20Dog%20%7B%0D%0A%20%20animaltype%3A%20%22Dog%22%2C%0D%0A%20%20color%3A%20string%2C%0D%0A%20%20likesToFetch%3A%20boolean%3B%0D%0A%7D%0D%0A%0D%0Aconst%20cat%3A%20Animal%20%3D%20%7B%0D%0A%20%20animaltype%3A%20%22Cat%22%2C%0D%0A%20%20color%3A%20%22brown%22%2C%0D%0A%20%20friendly%3A%20true%0D%0A%7D%3B

Related Issues:

@RikkiGibson
Copy link
Member Author

@mhegazy @DanielRosenwasser based on our chat yesterday

@mhegazy mhegazy added the Bug A bug in TypeScript label Jul 18, 2018
@mhegazy mhegazy assigned ghost Jul 18, 2018
@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 18, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jul 18, 2018

QuickInfo needs to do the same as well. Assuming you have multiple jsdoc comments for color on both Dog or Cat, the compiler should be smart enough to only pick one or the other based on the discriminant property type.

@ghost ghost added the Fixed A PR has been merged for this issue label Jul 25, 2018
@ghost ghost closed this as completed in #25914 Jul 25, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants