You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was creating some custom elements from a generic base class using LitElement and came to some odd problems where the analyzer didn't type-check generic-related properties.
A simplified version of what I was doing:
exportclassGenericElement<T>extendsLitElement{
@property()key!: keyofT}declare global {interfaceHTMLElementTagNameMap{'generic-specific': GenericElement<{id: number,name: string}>}}
First I tried to do it the vanilla way and type checking works fine:
constelement=document.createElement('generic-specific')element.key='what'// ✅ TS2322: Type '"what"' is not assignable to type '"id" | "name"'.
However, for some reason, it doesn't work in tagged html templates:
exportconstsomeTemplate=()=>html`<!-- ❌ Not type-checked --><generic-specifickey='what??'></generic-specific>`
I guess the analyzer doesn't analyze the declared generic part in the HTMLElementTagNameMap? because it thinks the key is of type keyof T instead of keyof { id: number, name: string }.
Would be glad to know what I'm missing or to know if there are work-arounds for now. Also, if these generic declarations cannot be supported due to some TypeScript API limitations, would it make sense to disable these checks for now?
The text was updated successfully, but these errors were encountered:
I was creating some custom elements from a generic base class using LitElement and came to some odd problems where the analyzer didn't type-check generic-related properties.
A simplified version of what I was doing:
First I tried to do it the vanilla way and type checking works fine:
However, for some reason, it doesn't work in tagged html templates:
I guess the analyzer doesn't analyze the declared generic part in the
HTMLElementTagNameMap
? because it thinks the key is of typekeyof T
instead ofkeyof { id: number, name: string }
.Would be glad to know what I'm missing or to know if there are work-arounds for now. Also, if these generic declarations cannot be supported due to some TypeScript API limitations, would it make sense to disable these checks for now?
The text was updated successfully, but these errors were encountered: