使用react+vite+ts创建的项目,我在项目根目录下创建了一个types文件夹,里面有一个global.d.ts
import { ReactNode } from "react"
declare interface PublicProps {
children?: ReactNode
}
我现在有个ui组件Pull.tsx。我想在不通过import的方式能直接使用我这个PublicProps
//Cannot find name 'PublicProps'
const Pull = (props:PublicProps) => {
return <div></div>
}
我的tsconfg.json如下
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",//"bundler",
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
}
},
"include": [
"src",
"types/**/*.d.ts",
],
"references": [{ "path": "./tsconfig.node.json" }]
}