Giter VIP home page Giter VIP logo

Comments (11)

sapphi-red avatar sapphi-red commented on June 16, 2024 1

It would be great if you can do it 😀

from vite.

jonlepage avatar jonlepage commented on June 16, 2024 1

thanks guys

from vite.

stackblitz avatar stackblitz commented on June 16, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from vite.

FreeJ1nG avatar FreeJ1nG commented on June 16, 2024

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.

bluwy avatar bluwy commented on June 16, 2024

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.

FreeJ1nG avatar FreeJ1nG commented on June 16, 2024

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.

sapphi-red avatar sapphi-red commented on June 16, 2024

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.

FreeJ1nG avatar FreeJ1nG commented on June 16, 2024

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.

FreeJ1nG avatar FreeJ1nG commented on June 16, 2024

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.

FreeJ1nG avatar FreeJ1nG commented on June 16, 2024

Created a PR here

from vite.

sapphi-red avatar sapphi-red commented on June 16, 2024

Closing as #16609 is merged.

from vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.