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

added TypeScript definitions for "html" and "svg" #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fogzot
Copy link

@fogzot fogzot commented Dec 29, 2021

The type definitions added by this commit are pretty basic, but enough to import and use the package from TypeScript.

Comment on lines +2 to +13
/** Renders the specified markup as an element, text node, or null as appropriate. */
const html: {
<T extends HTMLElement | Text | null>(...args: any[]): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: any[]): DocumentFragment;
};
/** Renders the specified markup as an SVG element, text node, or null as appropriate. */
const svg: {
<T extends SVGElement | Text | null>(...args: any[]): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: any[]): DocumentFragment;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly improved typings to have the proper tagged template string params (as per typings for String.raw):

Suggested change
/** Renders the specified markup as an element, text node, or null as appropriate. */
const html: {
<T extends HTMLElement | Text | null>(...args: any[]): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: any[]): DocumentFragment;
};
/** Renders the specified markup as an SVG element, text node, or null as appropriate. */
const svg: {
<T extends SVGElement | Text | null>(...args: any[]): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: any[]): DocumentFragment;
};
type TaggedTemplateParams = [
template: { raw: readonly string[] | ArrayLike<string> },
...substitutions: any[],
];
/** Renders the specified markup as an HTML element, text node, or null as appropriate. */
const html: {
<T extends HTMLElement | Text | null>(...args: TaggedTemplateParams): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: TaggedTemplateParams): DocumentFragment;
};
/** Renders the specified markup as an SVG element, text node, or null as appropriate. */
const svg: {
<T extends SVGElement | Text | null>(...args: TaggedTemplateParams): T;
/** Renders the specified markup as a document fragment. */
fragment(...args: TaggedTemplateParams): DocumentFragment;
};

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

Successfully merging this pull request may close these issues.

2 participants