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] Poor error message for missing type parameter constraint #6951

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

Description

@JoshuaKGoldberg

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.0.3&sourceType=module&code=KYDwDg9gTgLgBDAnmYcAKBDWiDSBLGAZRmgwHNUBeOAbwCg44AbPAZxgB4AVOagVwB2AawEQA7gIB8ACgCUALnRQIAWzbAOAWQxgO7KHgFkANHC6TJAbjoBfa3QAmwAMZMsqZxAHs4DgEaKmNj4RCRQ5MD2oJCwcBisiALOcABmgs4weF7MwABuwEwA4sAwcrQMcFAlfFACcNIYYhgEvn4AdCzscrJxrHDauvqGJnAAqoYwABwAglDhiFa2dEA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QOoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3QAacDUh4AhpgDm6PBSjoSRdAA8VUgL4g9QA

Repro Code

exporttypePartyKitStorage={list<T=unknown>():Promise<Map<string,T>>;};declareconstdb:PartyKitStorage;exportasyncfunctionlevelGet(){return(awaitdb.list())asMap<string,Uint8Array>;}

ESLint Config

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

tsconfig

{"compilerOptions": {"strict":true,"target":"esnext"  }}

Expected Result

Theas assertion is changing the type ofdb.list from the default inferredlist<unknown> tolist<Uint8Array>. Saying"This assertion is unnecessary since it does not change the type of the expression." is incorrect.

I think ideally I'd want the lint complaint to indicate that theas should be replaced with an explicit<Uint8Array> ondb.list... but I suspect that's quite a lot of work (what if there are many type parameters, and/or they have odd constraints?). So perhaps we should special case the rule's message for cases with type parameters? Not sure.

Actual Result

This assertion is unnecessary since it does not change the type of the expression.

Additional Info

Very similar to#5487 as filed by@srmagura.

Found in the wild trying to enablerecommended-requiring-type-checking onhttps://github.com/partykit/partykit/blob/baa74442a567b303ef0f93edcf3baa6622e0a749/packages/y-partykit/src/storage.ts#L54-L57 (partykit/partykit#125 (comment)).

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp