Make IntrinsicElements extends SvelteHTMLElements

so it can be extend with declare module
converting to module so it can extend without needing another type alias
pull/9070/head
Lyu, Wei Da 3 years ago
parent ab95ce897a
commit da84ae9c04

@ -1,11 +1,22 @@
/// <reference lib="dom" />
/* eslint-disable @typescript-eslint/no-empty-interface */
import * as svelteElements from './elements';
/**
* @internal do not use
*/
type HTMLProps<Property extends string, Override> = Omit<
import('./elements').SvelteHTMLElements[Property],
keyof Override
> &
Override;
declare global {
/**
* This namespace does not exist in the runtime, it is only used for typings
*
*/
declare namespace svelteHTML {
namespace svelteHTML {
// Every namespace eligible for use needs to implement the following two functions
/**
* @internal do not use
@ -20,7 +31,7 @@ declare namespace svelteHTML {
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
// "undefined | null" because of <svelte:element>
element: Key | undefined | null,
attrs: string extends Key ? import('./elements').HTMLAttributes<any> : Elements[Key]
attrs: string extends Key ? svelteElements.HTMLAttributes<any> : Elements[Key]
): Key extends keyof ElementTagNameMap
? ElementTagNameMap[Key]
: Key extends keyof SVGElementTagNameMap
@ -30,7 +41,7 @@ declare namespace svelteHTML {
// "undefined | null" because of <svelte:element>
element: Key | undefined | null,
attrsEnhancers: T,
attrs: (string extends Key ? import('./elements').HTMLAttributes<any> : Elements[Key]) & T
attrs: (string extends Key ? svelteElements.HTMLAttributes<any> : Elements[Key]) & T
): Key extends keyof ElementTagNameMap
? ElementTagNameMap[Key]
: Key extends keyof SVGElementTagNameMap
@ -43,20 +54,11 @@ declare namespace svelteHTML {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface SVGAttributes<T extends EventTarget = any> {}
/**
* @internal do not use
*/
type HTMLProps<Property extends string, Override> = Omit<
import('./elements').SvelteHTMLElements[Property],
keyof Override
> &
Override;
/**
* Avoid using this interface directly. Instead use the `SvelteHTMLElements` interface exported by `svelte/elements`
* This should only be used if you need to extend the interface with custom elements
*/
interface IntrinsicElements {
interface IntrinsicElements extends svelteElements.SvelteHTMLElements {
a: HTMLProps<'a', HTMLAttributes>;
abbr: HTMLProps<'abbr', HTMLAttributes>;
address: HTMLProps<'address', HTMLAttributes>;
@ -244,4 +246,5 @@ declare namespace svelteHTML {
[name: string]: { [name: string]: any };
}
}
}

Loading…
Cancel
Save