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

Rule proposal: check that function is not returning promise and non-promise #9296

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@benmccann

Description

@benmccann

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

We have a number of public APIs in our project that return things likestring | Promise<string>. In fact, we have so many of these that we have a helper type calledMaybePromise. I believe it would be better if these functions always returned aPromise. It would make a nicer API for callers because they would only have to worry about handling rejected promise errors and would not have to worry about errors that are thrown as well

I probably wouldn't want to apply this check to our whole project as internally we can have errors propagate in many functions, but I'd love to apply it to our public type definition file (.d.ts).

Fail Cases

exportinterfaceEmulator{platform(details:{config:any;prerender:PrerenderOption}):App.Platform|Promise<App.Platform>;}

Pass Cases

exportinterfaceEmulator{platform(details:{config:any;prerender:PrerenderOption}):Promise<App.Platform>;}

Additional Info

promise-function-async has a somewhat similar goal, but doesn't work for me because it ignores methods with explicit return types, which is one of the things I'd like to detect and disallow. It also has a ton of false positives on my existing codebase where it's almost always fine for me to just propagate errors upwards

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: 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