Typescript: Quick fix to 'declare function' from call site

Created on 17 Apr 2020  路  5Comments  路  Source: microsoft/TypeScript

Search Terms

declare function quick fix

Suggestion

Provide a quick fix for calls to unknown functions to declare a function of that name in current or module scope. Similar to the "declare method" quick fix for methods in classes.

Use Cases

Write code that consumes a function before writing it to let you figure out the order of arguments etc. Function parameter types and names should be inferred from arguments given at call site, just like "declare method".

Examples

declare x: boolean;
declare y: string;
foo(x, y, 123); // Cannot find name 'foo'

Cursor at squiggly -> Quick fix "Declare function in module scope" ->

declare x: boolean;
declare y: string;
foo(x, y, 123);

function foo(x: boolean, y: string, arg3: number) {
}

Checklist

My suggestion meets these guidelines:

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

All 5 comments

@RyanCavanaugh Should this feature be created as a new QF service or added to some of the existing ones?

@a-tarasyuk please don't implement features in the Awaiting More Feedback state - we can only take PRs for things assigned to the Backlog or a named release milestone

@RyanCavanaugh I think this issue related to https://github.com/microsoft/TypeScript/issues/26217 somehow, which is located in the Backlog milestone. However, don't worry I won't work on it. :hand::point_up:

@a-tarasyuk yes, I think that issue covers this.

Closing in favor of #26217

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanzer picture seanzer  路  3Comments

blendsdk picture blendsdk  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

dlaberge picture dlaberge  路  3Comments

wmaurer picture wmaurer  路  3Comments