gpt4 book ai didi

reactjs - 错误 TS2694 : Namespace '"react "' has no exported member ' ReactNode', 'DetailedHTMLProps' 'HTMLAttributes' 'SyntheticEvent' 'HTMLProps'

转载 作者:行者123 更新时间:2023-12-03 12:38:38 28 4
gpt4 key购买 nike

在我的 react-typescript-electron 项目中,我有:

"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0"
},
"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
这是我的 tsconfig.json 文件:
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node",
"lib": [
"dom",
"es2015",
"es2016",
"es2017",
"dom",
"dom.iterable",
],
"noImplicitAny": false,
"sourceMap": true,
"rootDir": "src",
"outDir": "dist",
"baseUrl": ".",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "esnext"],
"noEmitOnError": true,
"noImplicitReturns": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"removeComments": true,
"strict": true,
"downlevelIteration": true,
"declaration": true,
"alwaysStrict": true,
"skipLibCheck": true
},
"include": [
"src/**/*"
]
}
我收到这些错误消息:
对于此代码:
import React from 'react';
type Props = React.HTMLProps<HTMLDivElement, HTMLDivElement>
我收到此错误:
error TS2694: Namespace '"react"' has no exported member 'HTMLProps'.
type Props = React.HTMLProps<HTMLDivElement, HTMLDivElement>
对于此代码:
import React, { useState } from 'react';
interface Props {
summary: React.ReactNode;
children: () => React.ReactNode;
}
我收到这些错误:
 error TS2694: Namespace '"react"' has no exported member 'ReactNode'
summary: React.ReactNode;

error TS2694: Namespace '"react"' has no exported member 'ReactNode'
children: () => React.ReactNode;
对于此代码:
 import React from 'react'
type Value = React.ReactElement
我收到此错误:
 error TS2694: Namespace '"react"' has no exported member 
'ReactElement'
对于此代码:
import React, { useState } from 'react';
const onToggle = (e: React.SyntheticEvent) => {
我收到此错误:
error TS2694: Namespace '"react"' has no exported member 
'SyntheticEvent'
对于此代码:
import React from 'react';
type Props =
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement>
我收到这些错误:
error TS2694: Namespace '"react"' has no exported member  
'DetailedHTMLProps'
对于此代码:
import React, { Fragment } from 'react';
export default function LogLink({ v, children }: Props) {
function onClick(e: React.SyntheticEvent) {
我收到此错误:
error TS2694: Namespace '"react"' has no exported member 
'SyntheticEvent'
期待您的帮助。

最佳答案

感谢 Typescript Discord Group 的人,我发现在 modules.d.ts 中声明 react 和 react-dom 会干扰类型定义。
在 modules.d.ts 中删除这些定义后,所有这些错误都消失了

关于reactjs - 错误 TS2694 : Namespace '"react "' has no exported member ' ReactNode', 'DetailedHTMLProps' 'HTMLAttributes' 'SyntheticEvent' 'HTMLProps',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65032402/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com