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

Add SVGElementTagNameMap #14783

Closed
justinfagnani opened this issue Mar 22, 2017 · 5 comments · Fixed by microsoft/TypeScript-DOM-lib-generator#324 or #20177
Closed

Add SVGElementTagNameMap #14783

justinfagnani opened this issue Mar 22, 2017 · 5 comments · Fixed by microsoft/TypeScript-DOM-lib-generator#324 or #20177
Assignees
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@justinfagnani
Copy link

TypeScript Version: 2.2.1

APIs that use ElementTagNameMap or HTMLElementTagNameMap could benefit the same from a SVGElementTagNameMap.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 22, 2017

HTMLElementTagNameMap is only used for createElement, and as far as i understand createElement does not generate SVGElements, so what APIs did you have in mind?

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@falsandtru
Copy link
Contributor

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 SVGElementTagNameMap doesn't exist. Can you accept this PR?

@falsandtru
Copy link
Contributor

falsandtru commented Nov 18, 2017

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

@falsandtru
Copy link
Contributor

I made a PR microsoft/TypeScript-DOM-lib-generator#324

@falsandtru
Copy link
Contributor

@RyanCavanaugh @mhegazy Can you take a look?

@mhegazy mhegazy closed this as completed Nov 20, 2017
@mhegazy mhegazy added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet and removed Needs Investigation This issue needs a team member to investigate its status. labels Nov 20, 2017
@mhegazy mhegazy self-assigned this Nov 20, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 20, 2017
@mhegazy mhegazy reopened this Nov 20, 2017
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Nov 20, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 21, 2017
@mhegazy mhegazy removed the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Nov 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
4 participants