Skip to content
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

Misleading EPC error on deferred generic type when assigning any object literal, but empty object is also not assignable #56391

Open
fatcerberus opened this issue Nov 14, 2023 · 1 comment Β· May be fixed by #59901
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@fatcerberus
Copy link

fatcerberus commented Nov 14, 2023

πŸ”Ž Search Terms

N/A (bug report forked from #56388)

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAylC8UDeAPAXFA5AQwEYGNMBfAKADMBXAO32AEsB7KqMgHgBUoIVgIqATAM6wAfAAoAlMhJQo+JoOBR0yANoBrKHWbtVmFJgC6hjFQoBbXBABORBMjz4MARjsB6N1ACiABQDCXNbWDNYANCwhUNhUIFrm2ADm2ngANtDqECAycgpKIBhIGlo6egbGphZWtvZI7p7yQRC0UKCQgcHWJKRAA

πŸ’» Code

type S = {x: 'abc'}
function f<T extends S>() {
  const x: {[k in T['x']]: number} = {abc: 1} // EPC error, for any imaginable key
  const y: {[k in T['x']]: number} = {} // ...but this is also a (correct!) type error
}

πŸ™ Actual behavior

EPC diagnostic on any non-empty object literal, but {} is also not assignable.

πŸ™‚ Expected behavior

No EPC diagnostic; should just be a straight assignability failure.

Additional information about the issue

Producing an EPC (excess property check) error for any non-empty object literal here is misleading since that ultimately implies {} would be a legal value (it is not). 5.3 exacerbates this because it removes the "X is not assignable to Y" text from EPC diagnostics, which further implies that the value would be legal if assigned indirectly (also not true; the type is generic and might have other properties).

@fatcerberus
Copy link
Author

btw w.r.t. the issue template: Can there be a Summary field above Search Terms, so people stop trying to put the bug description into Search Terms? (tbh I almost made the same mistake--it's a bit confusing when you click the search terms box and it expands to a full-featured multiline field, especially since there's no designated place for a summary)

@fatcerberus fatcerberus changed the title Misleading EPC error on deferred generic type for any property Misleading EPC error on deferred generic type when assigning any object literal, hut empty object is also not assignable Nov 14, 2023
@fatcerberus fatcerberus changed the title Misleading EPC error on deferred generic type when assigning any object literal, hut empty object is also not assignable Misleading EPC error on deferred generic type when assigning any object literal, but empty object is also not assignable Nov 14, 2023
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Nov 14, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants