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

Update index.d.ts #26

Merged
merged 2 commits into from
Jan 20, 2020
Merged

Update index.d.ts #26

merged 2 commits into from
Jan 20, 2020

Conversation

mgenware
Copy link
Contributor

Use the right way to add custom element to TypeScript definitions.

Sadly, I didn't find any official docs on this matter, only some posts/repos:

Use the right way to add custom element to TypeScript definitions.

Sadly, I didn't find any official docs on this matter, only some posts/repos:
- https://justinfagnani.com/2019/11/01/how-to-publish-web-components-to-npm/
- https://github.com/runem/lit-analyzer/tree/master/packages/lit-analyzer#-no-unknown-tag-name
@koddsson
Copy link
Contributor

koddsson commented Jan 3, 2020

Hey @mgenware!

Is there any benefits to this way over our current way? I'd be hesitant to change this without a tangible benefit since I would want to update all the other elements we have so that they are uniform.

@mgenware
Copy link
Contributor Author

mgenware commented Jan 3, 2020

Well, I guess TypeScript-related tools may fail on this definition file. For us, it happens on lit-analyzer, which is used to lint our typescript codebase.

btw found more convincing examples:

The official TypeScript lib.dom.d.ts:

interface HTMLElementTagNameMap {
    "a": HTMLAnchorElement;
    "abbr": HTMLElement;
    "address": HTMLElement;
   /* ... */
}

Some random generated component file from stencil:

declare global {
  /* ... */
  interface HTMLElementTagNameMap {
    'hello-vdom': HTMLHelloVdomElement;
  }
}

angular.io:

declare global {
  interface HTMLElementTagNameMap {
    'my-dialog': NgElement & WithProperties<{content: string}>;
    'my-other-element': NgElement & WithProperties<{foo: 'bar'}>;
    ...
  }
}

Copy link
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

Thanks for all the references @mgenware, those are really helpful. It sucks that there aren't more documentation around this use case.

I think this change is good. It moves us to be more inline with other components and tools as well as the DOM definitions of TypeScript.

I'll look into updating this in our other components as well.

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

I think we want both. Having the entry in HTMLElementTagNameMap is helpful for APIs like querySelector('image-crop') but also we need to keep the type for window.ImageCropElement, given this line:

window.ImageCropElement = ImageCropElement

@koddsson koddsson merged commit 8140527 into github:master Jan 20, 2020
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.

3 participants