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

Bug: [no-unnecessary-type-assertion] false positive for Object.values #10722

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@TkDodo

Description

@TkDodo

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.7.3&fileType=.tsx&code=MYewdgzgLgBCBGArAXDA3gXxgXnRgsAFBED0JMA7iAE4DWEMAhgwKYAeADi8FCwCZFQkWADdGAGwCuLBrgDySblAB0YqTIAUCRAEpB4aEwgQW1XnwBqE6bJhqbRmNGoBLMAHMA2gF0A3EVJyADMJExgOEAgXKBcRFn1hGD4XaiVxAE8AQWNTcyt1WwVEJVVrTW0dR2c3Lz8AwiA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QeoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

constobj:{}={}// works as expectedconstvalues=Object.values(obj)constassertedValues=valuesasstring[];// false positiveconstdirectlyAssertedValues=Object.values(obj)asstring[];

ESLint Config

{"rules":{"@typescript-eslint/no-unnecessary-type-assertion":"error"}}

tsconfig

{"compilerOptions": {"strictNullChecks":true  }}

Expected Result

There should be no error in the provided playground

Actual Result

There’s an error in line 8:

This assertion is unnecessary since it does not change the type of the expression. 8:32 - 8:62

Additional Info

It seems that when we haveObject.values(obj) that returns anArray<unknown>, and we’d want to assert that to a more specific array, the rule thinks the assertion is unnecessary when it’s actually necessary.

Note that this doesn’t happen when we changeobj to beRecord<string, unknown>, so maybe this is specific to the type{}. I’m aware this type should generally be avoided, but I’m not sure how this makes a difference here.

The error can also be reproduced by inlining the object:Object.values({}).

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: 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