Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhancement: [ban-types] Allow {} in the recommended config #8697

Closed as not planned
Labels
blocked by another issueIssues which are not ready because another issue needs to be resolved firstenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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/ban-types

Description

The{} has long been a source of confusion in TypeScript. It means"any non-nullish value, but with no known fields". That includes objects like{} and{ value: 1 }, primitives liketrue and"", arrays like[], and general class instances likenew Error().

Because users so often get confused by{} allowing primitives liketrue and"", theban-types rule suggests users use something more restrictive. Specifically its default options include:

`{}` actually means "any non-nullish value".',- If you want a type meaning "any object", you probably want `object` instead.',- If you want a type meaning "any value", you probably want `unknown` instead.',- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.',- If you really want a type meaning "any non-nullish value", you probably want `NonNullable<unknown>` instead.',

That's pretty strict... at the cost of user convenience.

Now that#8364 is in, we have the ability to provide more lenient default options for therecommended* configs vs. thestrict* configs.

Proposal: let's remove the restriction on{} from the defaultban-types options inrecommended configs, and leave them in forstrict configs?

Fail

letvalue:Object;

Pass

letvalue:{};

Additional Info

@RyanCavanaugh, the dev lead for TypeScript, is not a fan of the way it is now 😄:https://bsky.app/profile/searyanc.dev/post/3knqtqcjhpn2d

See also#5947 for past discussion around objects andban-types

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked by another issueIssues which are not ready because another issue needs to be resolved firstenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp