Skip to content

'Types have no overlap' when extending Partial of generic type #47026

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
vostrnad opened this issue Dec 5, 2021 · 2 comments
Closed

'Types have no overlap' when extending Partial of generic type #47026

vostrnad opened this issue Dec 5, 2021 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@vostrnad
Copy link

vostrnad commented Dec 5, 2021

Bug Report

When comparing two variables of generic types, one of which extends the Partial of the other, TypeScript complains that the types have no overlap.

🔎 Search Terms

TS2367 partial generic

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Type System Behavior, Generics

⏯ Playground Link

Playground link with relevant code

💻 Code

const equal = <T, P extends Partial<T>>(item: T, partial: P) => {
  // incomplete implementation
  return item === partial // error
}

🙁 Actual behavior

The code above produces this error:
This condition will always return 'false' since the types 'T' and 'P' have no overlap.

🙂 Expected behavior

Since the types T and Partial<T> do overlap, I would expect the above code to compile without errors.

@RyanCavanaugh
Copy link
Member

Q: Why isn't the signature written this way?

const equal = <T,>(item: T, partial: Partial<T>) => {
  return item === partial // no error
}

The comparability check is necessarily incomplete (meaning errors more than it "should") to do anything useful; it's true that there's no assertion route from T to P here but that follows from our other rules. I'm not sure there's an improvement to be found here that doesn't make the comparability rule more confusing than it already is

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 7, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' 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
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants