question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom elements not compatible with React + Typescript

See original GitHub issue

Description:

When using Typescript with React, custom elements cause typescript errors such as Property 'a-scene' does not exist on type 'JSX.IntrinsicElements'. Installing @types/aframe does not address the issue. The errors go away when one manually defines the IntrinsicElements using the technique outlined in https://github.com/Microsoft/TypeScript/issues/15449#issuecomment-385959396. This is a tedious process as all tags and attributes for each element used must be defined. Another way to address this is to isolate the elements into a separate file where typescript checking is disabled, also not optimal.

  "devDependencies": {
    "@types/aframe": "^1.0.3",
  },
  "dependencies": {
    "aframe": "^1.2.0",
  },

The DefinitelyTyped entry for @types/aframe links here but should this be logged on the DefinitelyTyped repo instead? I consider this a big DX factor for aframe so I’m posting here first.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rajsitecommented, May 4, 2021

I think there are potentially more issue than just types when using React with web components. The library @lit-labs/react could potentially be used to wrap web components as React components but I haven’t tried it with aframe.

0reactions
jotatoledocommented, Dec 13, 2022

Seems like somebody already started an effort to create the corresponding jsx types. See here

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Web Components with TypeScript and React
So now we have type checking on our custom events for our Web Components in React and TSX. import React, { useState, DOMAttributes...
Read more >
Using web-components within Preact and typescript
I'm currently using typescript@v3.8.3 and preact@10.3.4 . typescript · web-component · custom-element · preact · Share.
Read more >
Consuming a Web Component in React in Typescript
The problem is React only knows about standard HTML Elements, so when I go putting my custom element in there, it doesn't know...
Read more >
Composing React Components with TypeScript - Pluralsight
Using TypeScript in React to compose components together ensures your ... with React and TypeScript presents some nuances that may not be ...
Read more >
Documentation - JSX - TypeScript
Type Checking · For React, intrinsic elements are emitted as strings ( React.createElement("div") ), whereas a component you've created is not ( React....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found