Closed as not planned
Closed as not planned
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
// no-unsafe-argument:
declare const a: { foo: any };
function foo(x: { foo: string }): { foo: string } {
return x;
}
// Unsafe argument of type `{ foo: any; }` assigned to a parameter of type `{ foo: string; }`.
foo(a);
declare const b: any[] | number;
function bar(x: string[] | number): string[] | number {
return x;
}
// Unsafe argument of type `number | any[]` assigned to a parameter of type `number | string[]`.
bar(b);
// similarly with `no-unsafe-return`
declare const c: { foo: any };
export function hello(): { foo: string } {
// Unsafe return of type `{ foo: any }` from function with return type `{ foo: string }`.
return a;
}
declare const d: any[] | number;
export function world(): string[] | number {
// Unsafe return of type `any[]` from function with return type `number | string[]`.
return b;
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-return": "error",
},
};
tsconfig
Expected Result
I expected the rule to fail on these, similarly to how it fails on similar boxed values like Promise<any>
, or any[]
, along with a combination of boxed values.
Actual Result
The code example is reporting no lint errors.
Additional Info
The no-unsafe-*
rule family misses some edge case checks, mostly around boxed values (like arrays, objects, promises, etc.). While you get a warning for most any
values wrapped in a box, I found some the rule misses around union and object types.
I made a simplified implementation to test-run on typescript-eslint's own repo and found one issue here (matching string[] | undefined
with any[]
).