Skip to content

Distinguish interfaces based on mutual exclusivity of their property type #29158

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
5 tasks done
zikaari opened this issue Dec 26, 2018 · 4 comments
Closed
5 tasks done
Labels
Duplicate An existing issue was already created

Comments

@zikaari
Copy link

zikaari commented Dec 26, 2018

Suggestion

If two (or more) interfaces have a property with the same name, but in none of those said interfaces does the property share same type. TS should be able to differentiate between those interface(s) when inside conditional blocks where the said property being compared against its possible types is part of the condition

Use Cases

It would eliminate having to use type casting and/or other ugly methods.

Examples

Described in Playground

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@ajafff
Copy link
Contributor

ajafff commented Dec 26, 2018

Duplicate of #27497

@zikaari
Copy link
Author

zikaari commented Dec 26, 2018

How can the TS AST not know that errorType comes from that value?

@fatcerberus
Copy link

The analyzer simply doesn't track that information. It's no different than if you assign the result of a type check to a variable; that variable won't act as a type guard later.

@weswigham weswigham added the Duplicate An existing issue was already created label Jan 2, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants