Skip to content

Fix completions of optional properties in generic positions - #33937

Merged
Andrew Branch (andrewbranch) merged 18 commits into
microsoft:masterfrom
andrewbranch:bug/30507
Oct 17, 2019
Merged

Andrew Branch (andrewbranch) merged 18 commits into
microsoft:masterfrom
andrewbranch:bug/30507

Conversation

@andrewbranch

@andrewbranch Andrew Branch (andrewbranch) commented Oct 10, 2019 •

Copy link
Copy Markdown
Member

Builds on #32100

Fixes #30507
Fixes #28470

Notable changes from #32100:

  • Doesn’t cache an alternative type during inference (Wesley Wigham (@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 Daniel Rosenwasser (@DanielRosenwasser) for that suggestion.

@timsuchanek

Copy link
Copy Markdown
Contributor

Awesome! Would be great to see this merged!

Copy link
Copy Markdown
Member

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.

Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
@AviVahl

Copy link
Copy Markdown
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
@andrewbranch

Copy link
Copy Markdown
Member Author

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

@andrewbranch
Andrew Branch (andrewbranch) merged commit a95a25b into microsoft:master Oct 17, 2019
@DanielRosenwasser

Copy link
Copy Markdown
Member

🎉

@timsuchanek

Copy link
Copy Markdown
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 */
})

Andrew Branch (@andrewbranch) can you confirm that this example is now working for you?

@timsuchanek

Tim Suchanek (timsuchanek) commented Oct 18, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

Tim Suchanek (@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
Copy Markdown
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

6 participants