I'm using custom-elements aka web-components within Preact. The problem is that Typescript complains about elements not being defined in JSX.IntrinsicElements
- in this case a check-box
element:
<div className={styles.option}>
<check-box checked={this.prefersDarkTheme} ref={this.svgOptions.darkTheme}/>
<p>Dark theme</p>
</div>
Error message (path omitted):
ERROR in MyComponent.tsx
[tsl] ERROR in MyComponent.tsx(50,29)
TS2339: Property 'check-box' does not exist on type 'JSX.IntrinsicElements'.
I came across the following, unfortunately not working, possible solutions:
- https://mcmap.net/q/156632/-typescript-complains-property-does-not-exist-on-type-39-jsx-intrinsicelements-39-when-using-react-createclass - It's an answer not really realted to the question but it covered my problem
I've tried adding the following to my typings.d.ts
file:
import * as Preact from 'preact';
declare global {
namespace JSX {
interface IntrinsicElements {
'check-box': any; // The 'any' just for testing purposes
}
}
}
My IDE grayed out the import part and IntrinsicElements
which means it's not used (?!) and it didn't worked anyway. I'm still getting the same error message.
- https://mcmap.net/q/829596/-typescript-error-quot-property-does-not-exist-on-type-39-jsx-intrinsicelements-39-quot-when-using-native-web-component - Also for react, I've tried to "convert" it to preact and I got the same results as for 1.
I've even found a file maintained by google in the squoosh project where they did the following to "polyfill" the support:
In the same folder as the component a
missing-types.d.ts
file with the following content, basically the same setup I have but with aindex.ts
file instead ofcheck-bock.ts
and they're using an older TS versionv3.5.3
:
declare namespace JSX {
interface IntrinsicElements {
'range-input': HTMLAttributes;
}
}
I'm assuming their build didn't fail so how does it work and how do I properly define custom-elements to use them within preact / react components?
I'm currently using [email protected]
and [email protected]
.