microsoft / microsoft/TypeScript
Confusing diagnostics with exact optional property types (EOPT)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
EOPT
exact optional property types
exactOptionalPropertyTypes
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about EOPT
⏯ Playground Link
💻 Code
// @strict: true
// @exactOptionalPropertyTypes: true
type A = { a?: number; b: string, z?: {} };
function f(a: A) { return a; }
f({ a: undefined, z: undefined });
// Argument of type '{ a: undefined; }' is not assignable to parameter of type 'A' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
// Property 'b' is missing in type '{ a: undefined; }' but required in type 'A'.(2379)
🙁 Actual behavior
Normally nested diagnostic messages are a refinement of their parents. In this case the inner diagnostic about property b is not related to the EOPT assignability issue in the head message. We have two different errors being represented in the same chain.
🙂 Expected behavior
There are several reasonable behaviors here.
- Do not change the parent message to the EOPT flavor when the inner message is not EOPT related
- Report two separate diagnostics
- Display both the current inner message and the EOPT mismatches at the same level
I would prefer option 2.
I have a working version of option 3 that I can a PR for if you want to go that route ( either as a permanent solution or a stop gap until further work on EOPT is done)
Argument of type '{ a: undefined; z: undefined; }' is not assignable to parameter of type 'A'.
Properties not assignable with exactOptionalPropertyTypes: a, z
Property 'b' is missing in type '{ a: undefined; z: undefined; }' but required in type 'A'.ts(2345)
Additional information about the issue
No response
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
Reproduce the diagnostic in the linked TypeScript Playground with strict and exactOptionalPropertyTypes enabled, using the supplied type and call. Compare the parent and nested messages and confirm with maintainers whether separate diagnostics, an unchanged parent, or the proposed same-level output is desired. Done means the unrelated missing-property diagnostic is no longer misleadingly nested under the EOPT diagnostic, with coverage for this example.
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
- 35/100