Skip to content
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

TS: "Declare method" is really bad #94118

Closed
bpasero opened this issue Apr 1, 2020 · 7 comments
Closed

TS: "Declare method" is really bad #94118

bpasero opened this issue Apr 1, 2020 · 7 comments
Assignees
Labels
typescript Typescript support issues upstream-issue-linked This is an upstream issue that has been reported upstream
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Apr 1, 2020

So many things wrong:

image

  • import uses a weird syntax
  • I am not being asked for the visibility, it is just public by default
  • any (!) is declared as return type??? I should be asked
@bpasero bpasero added the typescript Typescript support issues label Apr 1, 2020
@bpasero
Copy link
Member Author

bpasero commented Apr 1, 2020

With this, it took me more keystrokes to fix the method compared to just writing it myself.

@bpasero bpasero added the bug Issue identified by VS Code Team member as probable bug label Apr 1, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 1, 2020

Please provide steps to reproduce this issue in the VS Code codebase so we can investigate

@bpasero
Copy link
Member Author

bpasero commented Apr 1, 2020

@mjbvz in commandsQuickAccess#CommandsHistory add this._register(this.storageService.onDidChangeStorage(e => this.onDidChangeState(e))); into the registerListeners and then invoke quick fix on the error.

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 2, 2020

Thanks.

Point 1 is definitely a bug. I'll create a priority issue on TS for this

Point 2 is microsoft/TypeScript#36249 but for declare method. I'll open a separate issue for that

For point 3, TS should try to infer the return type based on context. In this case, the listener is typed to return any. Here's an example that shows this behavior:

function onSomething(e: (x: number) => number) { } // change this to 'any' to compare behavior

class Foo {
  bar() {
    onSomething(() => this.baz())
  }
}

The intent of quick fixes is to fix the issue, so we've avoid requiring user input on them

@mjbvz mjbvz added this to the April 2020 milestone Apr 2, 2020
@bpasero
Copy link
Member Author

bpasero commented Apr 2, 2020

TS should never suggest any. It is called TypeScript, not AnyScript 👍

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 2, 2020

But in your example, it's our code that explicitly says the listener returns any. We should change the return type of the listener if we don't want this to happen

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 3, 2020

  1. 'declare method' quick fix adds inline import TypeScript#37781

  2. 'declare method' quick fix for adding a private method TypeScript#37782

  3. Is as-designed since we use any in our code

@mjbvz mjbvz closed this as completed Apr 3, 2020
@mjbvz mjbvz added the upstream-issue-linked This is an upstream issue that has been reported upstream label Apr 28, 2020
@mjbvz mjbvz modified the milestones: April 2020, Backlog Apr 28, 2020
@mjbvz mjbvz removed the bug Issue identified by VS Code Team member as probable bug label Apr 28, 2020
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
typescript Typescript support issues upstream-issue-linked This is an upstream issue that has been reported upstream
Projects
None yet
Development

No branches or pull requests

2 participants