Skip to content

fix exact optional argument diagnostic#4228

Open
a-tarasyuk wants to merge 1 commit into
microsoft:mainfrom
a-tarasyuk:fix/4221
Open

fix exact optional argument diagnostic#4228
a-tarasyuk wants to merge 1 commit into
microsoft:mainfrom
a-tarasyuk:fix/4221

Conversation

@a-tarasyuk
Copy link
Copy Markdown
Contributor

Fixes #4221


else if (
    message === Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1
    && exactOptionalPropertyTypes
    && getExactOptionalUnassignableProperties(source, target).length
) {
    message = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties;
}

Copilot AI review requested due to automatic review settings June 6, 2026 16:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test and adjusts diagnostic selection so that, with exactOptionalPropertyTypes, argument assignability errors include a more specific message when optional properties are unassignable due to undefined.

Changes:

  • Introduces a new compiler test case + baselines for exactOptionalPropertyTypes argument errors.
  • Updates relation error reporting to emit a specialized diagnostic when exactOptionalPropertyTypes causes optional-property unassignability.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/exactOptionalPropertyTypesArgumentError.ts New repro test asserting the argument error messaging under exactOptionalPropertyTypes.
testdata/baselines/reference/compiler/exactOptionalPropertyTypesArgumentError.types Adds the expected type baseline for the new test.
testdata/baselines/reference/compiler/exactOptionalPropertyTypesArgumentError.symbols Adds the expected symbol baseline for the new test.
testdata/baselines/reference/compiler/exactOptionalPropertyTypesArgumentError.errors.txt Adds the expected error text baseline showing the specialized diagnostic.
internal/checker/relater.go Emits a more specific diagnostic when exactOptionalPropertyTypes is enabled and optional-property unassignability is detected.

Comment thread internal/checker/relater.go
Comment thread internal/checker/relater.go
@a-tarasyuk
Copy link
Copy Markdown
Contributor Author

@ahejlsberg Do we need to handle this case as Strada does, or is this a case where we're intentionally taking a different direction?

else if (
    message === Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1
    && exactOptionalPropertyTypes
    && getExactOptionalUnassignableProperties(source, target).length
) {
    message = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsgo reports TS2345 instead of TS2379 for exactOptionalPropertyTypes argument mismatches

2 participants