是否有可能来命名自己的自定义元素<date>,<person>,<city>或其他不使用破折号?没有它们可以使用定义元素吗?
我在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)
我遇到了以下可能的解决方案,但不幸的是无法正常工作:
我尝试将以下内容添加到我的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这意味着它没有被使用 (?!) 并且无论如何它都不起作用。我仍然收到相同的错误消息。
当我在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”类型上不存在属性?