-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add SVGElementTagNameMap #14783
Add SVGElementTagNameMap #14783
Comments
|
I want this too. When we make some SVGElement builder, need to define its type as createElement<K extends keyof SVGElementTagNameMap>(tagName: K): SVGElementTagNameMap[K]; to avoid the built-in method that requires specifying namespace URI. createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "a"): SVGAElement; But |
e.g. type TypedHTML = {
//readonly [K in keyof HTMLElementTagNameMap]: ElBuilder<K, HTMLElementTagNameMap[K]>;
readonly [K in keyof ElementTagNameMap]: ElBuilder<K, ElementTagNameMap[K]>;
};
export const TypedHTML: TypedHTML = new Proxy({} as TypedHTML, {
get: (obj, tag) =>
obj[tag]
? obj[tag]
: obj[tag] = builder(NS.HTML, `${tag}`),
});
/*
type TypedSVG = {
readonly [K in keyof SVGElementTagNameMap]: ElBuilder<K, SVGElementTagNameMap[K]>;
};
export const TypedSVG: TypedSVG = new Proxy({} as TypedSVG, {
get: (obj, tag) =>
obj[tag]
? obj[tag]
: obj[tag] = builder(NS.SVG, `${tag}`),
});
*/ function factory_(): E {
switch (ns) {
case NS.HTML:
return document.createElement(tag) as Element as E;
case NS.SVG:
return document.createElementNS("http://www.w3.org/2000/svg", tag) as Element as E;
default:
throw new TypeError(`TypedDOM: Namespace must be "${NS.HTML}" or "${NS.SVG}", but got "${ns}".`);
}
} https://github.com/falsandtru/typed-dom/blob/master/src/dom/html.ts |
I made a PR microsoft/TypeScript-DOM-lib-generator#324 |
@RyanCavanaugh @mhegazy Can you take a look? |
TypeScript Version: 2.2.1
APIs that use ElementTagNameMap or HTMLElementTagNameMap could benefit the same from a SVGElementTagNameMap.
The text was updated successfully, but these errors were encountered: