Skip to content

Issue a better error for exactOptionalPropertyTypes #44403

@DanielRosenwasser

Description

@DanielRosenwasser

A project under --strict will likely break in TypeScript 4.4, and it won't be obvious why.

foo/thing.ts:37:5 - error TS2322: Type 'SomeData | undefined' is not assignable to type 'SomeData'.
  Type 'undefined' is not assignable to type 'SomeData'.

37     data: data,
       ~~~~

What I would propose is that we give some better error message in these cases such as

The source property type 'SomeData | undefined' is not compatible with the target property type 'SomeData' under '--strictOptionalProperties'. Consider adding 'undefined' to the type of the target property.

This could then be given a quick fix.

We could give this error when

  • The source property is optional and the target type includes undefinedness
  • The types would otherwise be compatible if you were to remove the undefined from the target.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions