#How to extend props with native HTML element attributes?

1 messages · Page 1 of 1 (latest)

silk epoch
#

So far I have this code which I got from a post on here (I can't find it lol):

import type { HTMLAttributes } from 'astro/types';

type Fill = 'primary' | 'secondary' | 'accent' | 'danger';
type TagType = 'a' | 'button';

interface Props<Tag extends TagType> extends HTMLAttributes<'a' | 'button'> {
    icon?: boolean;
    fill?: Fill;
    link?: boolean; // style as link
    href?: string;
    as?: Tag & TagType;
}

I wanted to use the formmethod="dialog" in a dialog to close it automatically. But TypeScript is currently throwing an error when building

  Property 'formmethod' does not exist on type 'IntrinsicAttributes & Props<TagType>'.

107      <Button id="cancel" fill="accent" formmethod="dialog" formnovalidate>

How should I resolve this?

prime fjord
#

iirc formmethod can only be used on buttons with type="submit"

silk epoch
#

hmm I tried to add a type="submit" and typescript is still complaining

#

Also while MDN confirms your statement, their examples page just uses formmethod as is, no type="submit" required