-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Enable useSelect autocompletion #41911
Enable useSelect autocompletion #41911
Conversation
Size Change: +3.52 kB (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
Awesome work! This is probably my most wanted feature when working with
Any idea how we could solve this in the future?
Why wouldn't we want the |
@kevin940726 I somehow thought they're not being released – great spot! I am going to update the description to reflect that. The reason I wanted to avoid releasing was to test-drive these types internally and make any necessary adjustments before releasing them to the world. Since the build already includes types, adding {
"types": "build-modules",
"removeTypesResolutionOnBuild": true
} And remove the
We'd have to add |
Actually, a webpack plugin won't cut it as the package.json is bundled straight from |
Well then, maybe we could take this another way around. Don't add the IMO, I don't think we have to go all the way just to experiment with the types. For people not using TypeScript, the change doesn't matter to them. For people using TypeScript, they probably already have a custom config to ignore the type of the package anyway. I'd prefer just releasing the types in a minor release as a feature 😅. c.c. @gziolo for other concerns I missed though. |
I'd love that to be the case, but how do you know? Also, I just realized this would be a breaking change as right now the typescript reads the types from the DefinitelyTyped repo whereas after this PR it would start reading them from the data package. The culprit is the two are not compatible :( Also interested in your thoughts @dmsnell and @sarayourfriend |
Unfortunately, updating the tarball won't work. Lerna creates a temporary file with a random name and does not pass its path to Which means we can do either of:
I'd love to hear more opinions here. |
@kevin940726 I ended up going through with the ambient module declaration to enable this just in the Gutenberg repository for now. Would you be up for a re-review? Also cc @sirbrillig |
@@ -0,0 +1,3 @@ | |||
declare module '@wordpress/data' { | |||
export * from '@wordpress/data/build-types/index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this play with the issue of having a global DefinitelyTyped package in for @wordpress/data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overrides the DefinitelyTyped types thanks to the "typeRoots": [ "./typings", "./node_modules/@types" ],
setting in tsconfig.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see how this goes.
What?
This PR builds
@wordpress/data
types to provide autocompletion support foruseSelect
across the repository.The two included cosmetic changes in the
block-editor
package are here to showcase how it works:CleanShot.2022-06-23.at.13.44.33.mp4
Note: For now, this only works with the store defined in the same package where
useSelect
is called. With this PR, TypeScript knows how to resolve the type of theuseSelect
hook, but all the cross-package store imports still come across asany
.How
This PR adds a
wordpress__data.d.ts
ambient module that re-exports the types built for the@wordpress/data
package.The intention is to keep this change contained to the Gutenberg repository until the types mature more.
Once that happens, the next step would be publishing them by adding
"types": "build-types"
topackage.json
in@wordpress/data
. It tells TypeScript how to resolve the typing file for@wordpress/data
(source)Why?
Now that useSelect is typed in an autocompletion-friendly way, it only makes sense to enable that feature across the Gutenberg repository.
Testing Instructions
Go to
use-available-alignments.js
and confirm the autocompletion works as on the video above.CC @sarayourfriend @dmsnell @sirreal @jsnajdr @scruffian