Skip to content

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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"main": "src/index.js",
"module": "src/index.js",
"types": "src/index.d.ts",
"jsdelivr": "dist/htl.min.js",
"unpkg": "dist/htl.min.js",
"exports": {
Expand All @@ -19,7 +20,8 @@
"license": "ISC",
"files": [
"dist/**/*.js",
"src/**/*.js"
"src/**/*.js",
"src/**/*.d.ts"
],
"sideEffects": false,
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare module 'htl' {
/** 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;
};
Comment on lines +2 to +13

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;
};

export { html, svg };
}