Skip to content
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

When I attempt to extend HTMLAttributes every intrinsic element becomes of type any #4301

Closed
Zequez opened this issue Mar 12, 2024 · 2 comments

Comments

@Zequez
Copy link

Zequez commented Mar 12, 2024

This is the type declaration I'm using:

import { JSXInternal as JSXI } from 'preact/src/jsx';

declare module 'preact/src/jsx' {
  namespace JSXInternal {
    interface HTMLAttributes<T> extends JSXI.HTMLAttributes<T> {
      class?: any;
    }
  }
}

Essentially what I want to do is to extend the HTMLAttributes in order to be able to pass any type to the "class" attribute so I can then process it on the options.vnode hook; however when I use this declaration every element becomes of type any.

There was a long discussion a couple of years ago with something similar, but it was for extending IntrinsicElement not HTMLAttributes, and that thread is how I arrived to the current shape of the declaration file.

@rschristian
Copy link
Member

I believe this is what you want instead:

interface MyCustomProps {
  class?: any;
}

declare module 'preact' {
  namespace JSX {
    interface IntrinsicAttributes extends MyCustomProps {}
  }
  interface Attributes extends MyCustomProps {}
}

export {};

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Mar 17, 2024

Closing as answered - feel free to open things like this in discussions in the future, as these are more questions rather than issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants