Skip to content

Quick fix to 'declare function' from call site #38025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
markusjohnsson opened this issue Apr 17, 2020 · 5 comments
Closed
5 tasks done

Quick fix to 'declare function' from call site #38025

markusjohnsson opened this issue Apr 17, 2020 · 5 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@markusjohnsson
Copy link
Contributor

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:

  • 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.
@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Apr 17, 2020
@a-tarasyuk
Copy link
Contributor

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

@RyanCavanaugh
Copy link
Member

@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

@a-tarasyuk
Copy link
Contributor

a-tarasyuk commented Apr 18, 2020

@RyanCavanaugh I think this issue related to #26217 somehow, which is located in the Backlog milestone. However, don't worry I won't work on it. ✋☝️

@markusjohnsson
Copy link
Contributor Author

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

@markusjohnsson
Copy link
Contributor Author

Closing in favor of #26217

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants