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

Docs: [no-unnecessary-condition] mention subtleties of primitives' assignability #10970

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updating
@kirkwaiblinger

Description

@kirkwaiblinger

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

I'd like to add a section thatbriefly alerts users to the nuances around primitives being assignable to object types, causing sort-of-false-positives with no-unnecessary-condition's truthiness checks.

I'd like to mention:

  • "object types" are just "things with properties",not objects (a superset ofno-empty-object-type shenanigans)

    functionfoo(x:{toString:Function}){if(x){// reported by no-unnecessary-condition as always-truthy}}foo(false);foo(true);foo({});
  • object can easily contain primitives at runtime, without typical obviously unsafe TS patterns.

    functionfoo(o:object){if(o){// reported by no-unnecessary-condition as always-truthy}}foo(false);// TS error.constlol:{}=false;foo(lol);// but this is allowed by TS.

As said, I think this should bebrief, just to alert users to possibly-faulty common assumptions about the type system, and then punt deeper dive tomicrosoft/TypeScript#60582 (comment) or any other good references. The main goal is really to conveythink closely about your application before "fixing" a truthiness report, since the condition may actually be necessary, despite what the types appear to be indicate.

Affected URL(s)

https://main--typescript-eslint.netlify.app/rules/no-unnecessary-condition#limitations

Additional Info

Relates to#10378, which may eventually change some of this behavior. But regardless of rule behavior change on our side, it's valuable for users to know that primitives may be lurking places they didn't expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updating

    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