Skip to content

Enable to write async functions with the defined return type more simply, from :Promise<typename> to :typename@ #40425

Closed
@kamektx

Description

@kamektx

Search Terms

Promise, Abbreviation, At sign, At symbol

Suggestion

Now, in TypeScript, when you write the async function with the return type defined, you need to write like the following;

const myFunc = async (): Promise<boolean> => { 
    <...Tasks...>
    return true; 
}

However, it is redundant to write Promise<boolean> or Promise<number>.

The Array type has shortened forms such as boolean[] and number[], so it would be a good idea to write Promise<boolean> and Promise<number> as boolean@ and number@ by referring to them.

Use Cases

When you write async functions/methods.

Examples

Before

const myFunc1 = async (): Promise<boolean> => { return true; }
const myFunc2 = async (): Promise<number[]> => { return [1, 2, 3]; }

After

const myFunc1 = async (): boolean@ => { return true; }
const myFunc2 = async (): number[]@ => { return [1, 2, 3]; }

Checklist

My suggestion meets these guidelines:

  • [?] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [✓] This wouldn't change the runtime behavior of existing JavaScript code
  • [✓] This could be implemented without emitting different JS based on the types of the expressions
  • [✓] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [?] This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions