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

no-unsafe-call: ban calling Function #9108

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@kirkwaiblinger

Description

@kirkwaiblinger

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Unintuitively, TS narrowstypeof x === 'function' to the unsafeFunction type if x is not already constrained. However, it is safe to use on a constrained type. We should report on unconstrained callables.

Fail Cases

declareconstmaybeFunction:unknown;if(typeofmaybeFunction==='function'){// TS allows this.maybeFunction('call','with','any','args');}

Pass Cases

declareconstmaybeFunction:string|(()=>string);if(typeofmaybeFunction==='function'){// TS errors if more args are provided than the declared call signature, so this is safe.maybeFunction();}

Additional Info

it's probably fine/good to allowtypeof x === 'function as long asx isn't called. I'm not sure exactly where the line should be drawn between reporting and not reporting. It seems like it should be reported if wepassx to a function that might expect a specific call signature. Maybe a heuristic could betypeof x === 'function is ok as long asx isn't referenced in thetrue branch of the conditional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp