Comments (11)
It would be great if you can do it 😀
from vite.
thanks guys
from vite.
Start a new pull request in StackBlitz Codeflow.
from vite.
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
from vite.
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 .d.ts
file for it to work, which is understandably a bit odd compared to other typescript augmentations, but I think that pattern should also work.
from vite.
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
.d.ts
file for it to work, which is understandably a bit odd compared to other typescript augmentations, but I think that pattern should also work.
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 😅
from vite.
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 "moduleResolution": "bundler"
is used. I guess it's because we export it like this.
from vite.
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
"moduleResolution": "bundler"
is used. I guess it's because we export it like this.
That definitely fixed it!
Shall I create a PR to fix the wording in the docs? or is it not necessary?
from vite.
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
Instead of: https://vitejs.dev/guide/api-plugin#typescript-for-custom-events
And maybe there could be a link in api-plugin
referring to the one in api-hmr
What do you think about that?
from vite.
Created a PR here
from vite.
Closing as #16609 is merged.
from vite.
Related Issues (20)
- Vite config loadEnv exposing all envs to frontend. HOT 7
- AsideSponsors is outdated HOT 1
- Build --watch need HMR HOT 2
- Proxy processing OPTIONS requests will always return a 204 response HOT 3
- Vite `--watch` mode break after first change (Vite v.5.X) HOT 2
- Sourcemap for "xxx" points to missing source files, while inject `script.src` to index.html HOT 3
- Uncaught TypeError: t._reverse is not a function HOT 6
- ReferenceError: Cannot access 'q' before initializatio
- [vite] Internal server error: Missing "./../etc/passwd" export in "vite" package
- vue3 import() import variables HOT 1
- package.json - JSON does not support comments HOT 1
- Symlink only supports set of libararies HOT 2
- Service worker files do not get chunked HOT 2
- Infinite HMR loop if circular dep calls `import.meta.hot.invalidate()`
- when upgrade NodeJS up to v20+ local proxy not work HOT 1
- The `proxyGuardOnlyEsm` does not work consistently HOT 2
- Missmatch between dev / build for typescript files with ?url HOT 2
- `vite.config.ts` should resolve alias from `compilerOptions.paths` in `tsconfig.json` HOT 9
- Vite duplicates code across main bundle and web worker bundle
- Tree-shaking ineffective in default mode, removes all program code in `"smallest"` mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite.