我不断收到来自 node_modules 库中 TS 文件的警告,这是我不想看到的。
有问题的图书馆在这里:https ://github.com/xdan/jodit
我在我的 app.tsx 中导入库,如下所示:
import { IControlType, IJodit, Jodit } from 'jodit';
这是我的 tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
// "forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noErrorTruncation": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"outDir": "build",
"resolveJsonModule": true,
"paths": {
"src/*": ["src/*"]
},
"sourceMap": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5"
},
"include": ["src"],
"exclude": [
"**/*.spec.ts",
"**/node_modules",
"build",
"node_modules",
"scripts",
"src/serviceWorker.ts",
"src/vendors/**/*"
]
}
现在,我试过skipLibCheck: true
了,但这并没有解决问题。
- 我真的不想仅仅因为一个包就禁用 libCheck for ALL
- 无论如何它都没有用,因为如果我理解正确,即使我跳过了 lib 检查,TS 也会检查文件,因为文件是在我的项目中导入的
在我的 webpack 配置中,我有这个:
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
enforce: 'pre',
use: [
{
options: {
cache: true,
eslintPath: require.resolve('eslint'),
formatter: require.resolve('react-dev-utils/eslintFormatter'),
resolvePluginsRelativeTo: __dirname,
emitError: isEnvProduction,
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
}
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
}),
async: isEnvDevelopment,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
resolveModuleNameModule: process.versions.pnp ? `${__dirname}/pnpTs.js` : undefined,
resolveTypeReferenceDirectiveModule: process.versions.pnp
? `${__dirname}/pnpTs.js`
: undefined,
tsconfig: paths.appTsConfig,
reportFiles: [
'**',
'!**/__tests__/**',
'!**/?(*.)(spec|test).*',
'!**/src/setupProxy.*',
'!**/src/setupTests.*',
],
silent: true,
// The formatter is invoked directly in WebpackDevServerUtils during development
formatter: isEnvProduction ? typescriptFormatter : undefined,
})
我不知道这里是否有办法忽略这个库的错误?
我在控制台中遇到的错误是这样的错误:
react/assets/node_modules/jodit/src/modules/toolbar/collection/editor-collection.ts(40, 4)
Type 'boolean | void' is not assignable to type 'boolean'