microsoft / microsoft/TypeScript
Misleading EPC error on deferred generic type when assigning any object literal, but empty object is also not assignable
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
N/A (bug report forked from #56388)
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the linked TypeScript Playground example and compare the diagnostics for the non-empty and empty object literals in the generic mapped-type case. Trace the compiler's excess property checking and assignability decision for this pattern; done means the non-empty literal receives a regular assignability failure rather than an EPC diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100