Skip to content

Fix completions of optional properties in generic positions #33937

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

Merged
merged 18 commits into from
Oct 17, 2019

Conversation

andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Oct 10, 2019

Builds on #32100

Fixes #30507
Fixes #28470

Notable changes from #32100:

  • Doesn’t cache an alternative type during inference (@weswigham’s change request on the original PR)
  • Rather than getting the contextual type from the base signature alone, this intersects the types from the base signature and the resolved signature, so that in a case like
type U = { x: boolean };
declare function f<T extends Partial<U>>(x: T, y: T)

f({ a: true }, { /**/ });

you get completions for both x and a. Thanks to @DanielRosenwasser for that suggestion.

@timsuchanek
Copy link
Contributor

Awesome! Would be great to see this merged!

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test idea plus some nits.

@AviVahl
Copy link

AviVahl commented Oct 16, 2019

@andrewbranch this also fixes #28470

@andrewbranch
Copy link
Member Author

Ugh, committing PR review suggestions from GitHub UI doesn’t work in checker.ts 😑

@andrewbranch andrewbranch merged commit a95a25b into microsoft:master Oct 17, 2019
@andrewbranch andrewbranch deleted the bug/30507 branch October 17, 2019 17:45
@DanielRosenwasser
Copy link
Member

🎉

@timsuchanek
Copy link
Contributor

Very excited to see this merged 🙏
One question: How can I try it out in VSCode?
Unfortunately I'm not able to use this properly yet, even though setting "typescript.tsdk" in my settings.json to node_modules/typescript/lib .

This example should now work in VSCode and show world as a completion:

interface MyOptions {
  hello?: boolean
  world?: boolean
}
declare function bar<T extends MyOptions>(options?: Partial<T>): void

bar({
  hello: true,
  /* cursor */
})

@andrewbranch can you confirm that this example is now working for you?

@timsuchanek
Copy link
Contributor

timsuchanek commented Oct 18, 2019

I added a small PR to add exactly that test case, as it's important for us at Prisma that this one works.

#34559

@andrewbranch
Copy link
Member Author

@timsuchanek yep, that example works in VS Code for me:

image

setting "typescript.tsdk" in my settings.json to node_modules/typescript/lib.

If you’re building the source from master, you want to set the path to built/local. The one in the repo’s node_modules is just whatever the nightly was whenever you last did a clean npm install 😄

@timsuchanek
Copy link
Contributor

Awesome. I didn't know about the built/local. That also works for me.
Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants