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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
export type PartyKitStorage = {
list<T = unknown>(): Promise<Map<string, T>>;
};
declare const db: PartyKitStorage;
export async function levelGet() {
return (await db.list()) as Map<string, Uint8Array>;
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "error",
},
};
tsconfig
Expected Result
The as
assertion is changing the type of db.list
from the default inferred list<unknown>
to list<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 the as
should be replaced with an explicit <Uint8Array>
on db.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 enable recommended-requiring-type-checking
on https://github.com/partykit/partykit/blob/baa74442a567b303ef0f93edcf3baa6622e0a749/packages/y-partykit/src/storage.ts#L54-L57 (partykit/partykit#125 (comment)).