1 回答

TA貢獻1798條經驗 獲得超3個贊
undefined當可選值可能是打字稿或null打字稿時,您應該準確設置它們的類型。如果您處于strict模式下,針對這種情況有兩種選擇:
undefined1.設置s和nulls的類型
interface InputNumberProps {
className?: undefined | string | (string | undefined | null)[];
}
2. 將您的更改tsconfig為跳過檢查null和undefined:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "dom"],
"types": ["node", "jest"],
"jsx": "react",
"moduleResolution": "node",
"sourceMap": true,
"allowJs": false,
"strict": true,
"strictNullChecks": false, // this will skip that checking
"declaration": true,
"esModuleInterop": true
},
"exclude": ["src/**/__tests__/**"]
}
添加回答
舉報