react-script-hook icon indicating copy to clipboard operation
react-script-hook copied to clipboard

Script attribute types are treated as having an unknown shape

Open miwitham opened this issue 3 years ago • 0 comments

The current type used for ScriptProps is as follows:

export interface ScriptProps {
    src: HTMLScriptElement['src'] | null;
    checkForExisting?: boolean;
    [key: string]: any;
}

Where the type of attributes added to the <script> tag with the exception of the src key are [key: string]: any. As the attributes are specifically added to a <script> tag I believe a better typing might be provided by the following:

type ScriptAttributes = Omit<HTMLScriptElement, 'src'>;

export interface ScriptProps extends ScriptAttributes {
    src: HTMLScriptElement['src'] | null;
    checkForExisting?: boolean;
}

With src omitted for the sake of not stepping on the logic that makes use of the null value.

miwitham avatar Dec 11 '22 19:12 miwitham