Sen*_*Sen 13 typescript reactjs react-native
我运行了 React Native 项目以及官方文档,并将 TypeScript 添加到了该项目中。当我执行“yarn tsc”时,发生了许多 ESlint 错误,例如:
App.tsx:10:14 - error TS2305: Module '"react"' has no exported member 'Node'.
10 import type {Node} from 'react';
Run Code Online (Sandbox Code Playgroud)
我知道这只是一个 TS 错误,但我很困惑,为什么代码“import type {Node} from 'react';”会产生此错误
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es2017"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
Run Code Online (Sandbox Code Playgroud)
jse*_*ksn 12
因为 React 不导出名为Node
. 也许您正在寻找ReactNode
?
import type {Node} from 'react'; // error
import type {ReactNode} from 'react'; // ok
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9766 次 |
最近记录: |