Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: [consistent-type-assertions] Suggest alternate styles for objectLiteralTypeAssertions #6607

Closed
@NotWoods

Description

@NotWoods

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/consistent-type-assertions/

Description

With the objectLiteralTypeAssertions option turned on, we can suggest code changes to either swap to a type annotation or to use satisfies.

Since these both change TypeScript's behaviour, I thought it would be better to have them as suggestions instead of autofixes.

Fail

const x = { ... } as T;

Pass

const x: T = { ... }; // autofix for variable declarators
const x = { ... } satisfies T; // autofix for TypeScript 4.9+

Additional Info

Happy to open a PR. I've previously implemented this in a Microsoft repo and would like to bring it upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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