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 on type narrowing #11242

Closed as not planned
Labels
bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended
@cainlevy

Description

@cainlevy

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.8.3&fileType=.tsx&code=C4TwDgpgBAYgdlAvFA3gWAFBSgHgEpQQAewEcAJgM5SXABOAlnAOZQA%2BUArhRAGZMRyAPgAUASgBcUPAG5MAX0wBjAPZxaUYFPhIo4pEK49%2BcQXIyZe3JcAZqoAGxWUIAeToAZZxHFTajFnYoOE4AWwAjCDpUTGwGXj0AWQBDYAALADo6ZIoVUP0hZAAGDIBWMRisbCg6CGBOOgRgfWTqfyZmc2x5QgcXSuqauoam8S6oRQxJoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QOoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDArugDTg10NM8AOXapUAYQAW6aAGsylDul4BfECqA&tokens=false

Repro Code

typeFn={<Rextendsstring|undefined>():R;}constt:Fn=()=>undefined;functionloseOrLose():string|number{if(Math.random()>=0.5){// no-unnecessary-type-assertion thinks the "as string" is unnecessaryreturnt()asstring;}else{// but without `as string` typescript failsreturnt();}}

ESLint Config

module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/no-unnecessary-type-assertion":"error"},};

tsconfig

{"compilerOptions": {"strict":true,"strictNullChecks":true  }}

Expected Result

I expected thatas string would be allowed, since TypeScript fails without it.

Actual Result

no-unnecessary-type-assertion claims theas string is unnecessary

Additional Info

This is similar to#11054, but I do not know if it has the same root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    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