What's the strategy for asserting DOM elements as custom elements in TypeScript? #899
Answered
by
xdev1
andyjessop
asked this question in
Help
-
I'm trying to access a custom element and call an API method on it, but I get TS errors because document.getElementById(alert.id)?.toast(); // Property 'toast' does not exist on type 'HTMLElement'.
(document.getElementById(alert.id) as ShoelaceElement)?.toast(); // Property 'toast' does not exist on type 'ShoelaceElement'. |
Beta Was this translation helpful? Give feedback.
Answered by
xdev1
Sep 5, 2022
Replies: 1 comment 1 reply
-
What about the following? (document.getElementById(alert.id) as SlAlert)?.toast(); or document.querySelector<SlAlert>(`#${alert.id}`)?.toast(); How shall |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
andyjessop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about the following?
or
How shall
getElementById
(orShoelaceComponent
) know about the concrete element type without anyone declaring it explicitly?