相关疑难解决方法(0)

自定义元素的名称是否需要短划线?

是否有可能来命名自己的自定义元素<date>,<person>,<city>或其他不使用破折号?没有它们可以使用定义元素吗?

web-component x-tag polymer

40
推荐指数
1
解决办法
9299
查看次数

在 Preact 和 typescript 中使用 web 组件

我在Preact 中使用自定义元素又名 web 组件。问题是 Typescript 抱怨元素没有被定义在- 在这种情况下是一个元素:JSX.IntrinsicElementscheck-box

<div className={styles.option}>
    <check-box checked={this.prefersDarkTheme} ref={this.svgOptions.darkTheme}/>
    <p>Dark theme</p>
</div>
Run Code Online (Sandbox Code Playgroud)

错误信息(省略路径):

ERROR in MyComponent.tsx
[tsl] ERROR in MyComponent.tsx(50,29)
      TS2339: Property 'check-box' does not exist on type 'JSX.IntrinsicElements'.

Run Code Online (Sandbox Code Playgroud)

我遇到了以下可能的解决方案,但不幸的是无法正常工作:

  1. /sf/answers/4021468951/ - 这是一个与问题无关的答案,但它涵盖了我的问题

我尝试将以下内容添加到我的typings.d.ts文件中:

ERROR in MyComponent.tsx
[tsl] ERROR in MyComponent.tsx(50,29)
      TS2339: Property 'check-box' does not exist on type 'JSX.IntrinsicElements'.

Run Code Online (Sandbox Code Playgroud)

我的 IDE 使导入部分变灰,IntrinsicElements这意味着它没有被使用 (?!) 并且无论如何它都不起作用。我仍然收到相同的错误消息。

  1. /sf/answers/3879734491/ - 同样为了反应,我试图将它“转换”为 preact,我得到了与 1 相同的结果。

我什至在squoosh项目中找到了一个由 google 维护的文件 …

web-component typescript custom-element preact

9
推荐指数
3
解决办法
3551
查看次数

类型“JSX.IntrinsicElements”上不存在属性“div”。当我用 vite 创建 React TypeScript 项目时

当我在VScode中使用vite创建react typescript项目时,App.tsx中总是出现错误。

Property 'div' does not exist on type 'JSX.IntrinsicElements'.
Property 'a' does not exist on type 'JSX.IntrinsicElements'.Property 'img' does not exist on type 'JSX.IntrinsicElements'.
Run Code Online (Sandbox Code Playgroud)

我用vite创建项目 npm create vite@latest npm install npm i -D @types/react-dom

在浏览器中可以运行,但vscode中总是报错。我尝试了一些解决方案,但它不起作用。

tsconfig.json 中也有一些错误

Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
Run Code Online (Sandbox Code Playgroud)

我会将App.js和tsconfig.json放在附件中。

使用 React.createClass 时,Typescript 抱怨“JSX.IntrinsicElements”类型上不存在属性?

typescript 突然对我大喊所有 p 标签 - “属性 'p' …

typescript reactjs vite

6
推荐指数
1
解决办法
4410
查看次数