typescript - Komponent kan inte användas som en JSX-komponent. Egenskapen '$props' saknas i typ X men krävs i typ 'ElementClass'
Jag får detta TypeScript-fel från i princip varje komponent i VSCode, både anpassade och bibliotekskomponenter. Detta är en Expo-byggnad för React Native. Detta kommando ger samma resultat: yarn tsc --project tsconfig.json
här är ett exempel i VSCode
och ett exempel på hela felmeddelandet:
'KeyboardAvoidingView' cannot be used as a JSX component.
Its instance type 'KeyboardAvoidingView' is not a valid JSX element.
Property '$props' is missing in type 'TimerMixin & KeyboardAvoidingViewComponent' but required in type 'ElementClass'.ts(2786)
Det här är min .tsconfig:
{
"extends": "../../node_modules/expo/tsconfig.base",
"compilerOptions": {
"jsx": "react-native",
"strict": true
}
}
och detta är expos som det utökar:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Expo",
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "ESNext"
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}
Svar #1
Jag hade samma problem, jag lade bara till detta i package.json och sedan körde jag yarn
"resolutions": {
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2"
},
som nämnts här
