Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
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
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)).