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
ViteHotContext
type should be customizable
#16601
Comments
Start a new pull request in StackBlitz Codeflow. |
I tried changing the vite source code for HMR types to not use imports at the top level, as suggested on TS' documentation. I'm out of ideas on how to create the proper overridable types for the HMR declaration type |
If you're adding custom events, have you tried this? https://vitejs.dev/guide/api-plugin.html#typescript-for-custom-events It would be in a separate |
Hi Bjorn, Thanks for the reply, I definitely missed that part of the docs! my bad I tried following the example there, here is the code UPD: I changed the stackblitz link since the previous link used an old vite version, but it still doesn't work properly It still casts the payload to any, I'm not quite sure if I messed something up 😅 |
It seems it needs to be (notice the extension): import 'vite/types/customEvent.d.ts';
declare module 'vite/types/customEvent.d.ts' {
interface CustomEventMap {
'custom:myCustomEvent': number;
}
} It seems we need the extension when |
That definitely fixed it! Shall I create a PR to fix the wording in the docs? or is it not necessary? |
It would be great if you can do it 😀 |
Will do 🫡 I also think this part of the docs would be a better fit in the HMR API section rather than Plugin API, since it's a customization of the custom event type used in HMR So here: https://vitejs.dev/guide/api-hmr.html#further-reading And maybe there could be a link in What do you think about that? |
Created a PR here |
thanks guys |
Closing as #16609 is merged. |
Describe the bug
I am trying to add custom events in addition to the current
CustomEventMap
, and i'd want the payload type of the custom events to be typed properlyReproduction
https://stackblitz.com/edit/vitejs-vite-pkygn6?file=src%2Fvite-env.d.ts
Steps to reproduce
npm install
npm run dev
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: