Skip to content

Enhancement: [no-duplicate-type-constituents] Add checkOptionalProperties option, intended for projects without exactOptionalPropertyTypes enabled #12434

Description

@mathiashsteffensen

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-duplicate-type-constituents/

Description

I propose that no-duplicate-type-constituents supports a checkOptionalProperties option.

Similar to #9203 - when a property is marked as optional with ?, it implicitly includes undefined in the type definition, so there is no need to explicitly add an | undefined. I'd like to detect these cases and also autofix away the | undefined.

Note that this is explicitly incompatible with the exactOptionalPropertyTypes compiler option, that the rule otherwise is intended to not conflict with (see e.g. #5344). The documentation should clearly state that this option is intended for projects where exactOptionalPropertyTypes is NOT enabled.

Fail

type T = {
  a?: string | undefined
}

Pass

type T = {
  a?: string
}

Additional Info

I would be more than happy to create a PR that implements this :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleevaluating community engagementwe're looking for community engagement on this issue to show that this problem is widely importantpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions