Skip to content

Bug: [no-unsafe-argument] doesn't flag unsafe argument with a type constraint #10415

Open
@ronami

Description

@ronami

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

https://typescript-eslint.io/play/#ts=4.8.4&fileType=.tsx&code=CYUwxgNghgTiAEYD2A7AzgF3hkmCMAXPABQZEoCuAtgEYgwCU8AvAHzwBuSAlsANwAoUJFgJk6LDkwAmIgB4AKvBAAPHCmBp4lWvVakiCpm049%2BAgQHpL8AGZRuELchhwwGCAE8BUjHmJ48FBaUCieDIJWNmgAFkgUEMB2DhA%2BuBjSAUEhYRECQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZolp9oAc1gBbRC3RRE0aB2iRwYAL4h1QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare const test1: (t: number) => void;
declare const test2: <T extends number>(t: T) => void;

// fails correctly
test1(1 as any);

// should fail
test2(1 as any);

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unsafe-argument": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I expect all use-cases to be consistent and report this as an error.

Actual Result

The use-cases with a type constraint doesn't report this as an error.

Additional Info

This seems similar to #10314, and it looks like the fix should be similar.

I'll add that I see similar inconsistencies on no-unsafe-assignment and no-unsafe-return (false positives, in which the rule reports unnecessarily):

// no-unsafe-return
declare const test1: (callback: () => unknown) => void;
declare const test2: <T>(callback: () => T) => void;
declare const test3: <T extends unknown>(callback: () => T) => void;

// passes correctly
test1(() => 1 as any);

// should pass
test2(() => 1 as any);

// should pass
test3(() => 1 as any);

// no-unsafe-assignment
declare const test4: (t: { t: unknown }) => void;
declare const test5: <T extends unknown>(t: { t: T }) => void;

// pass correctly
test4({ t: 1 as any });

// should pass
test5({ t: 1 as any });

I'll be happy also to report them (separately or as part of this issue) if this makes sense.

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