tsc无法识别引用的yarn工作区类型,但它们适用于VS代码



我有一个monoreo,其中我有两个使用TypeScript、/ui和/graphql的工作区

/ui引用/graphql,VS代码可以从中获取类型、添加导入、自动完成属性等。但是,当我尝试为/ui执行tsc --build时,它会抛出关于找不到导入模块的错误:

以下是/graphql:的tsconfig

{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"composite": true,
"jsx": "react",
"declaration": true,
"declarationMap": true,
"noEmit": false,
"outDir": "build",
"rootDir": "src"
},
"include": ["**/*.tsx", "**/*.ts"],
"exclude": ["build"]
}

这是tsconfig:的基本配置

{
"compilerOptions": {
"incremental": true,
"noEmitOnError": true,
"allowJs": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "preserve",
"lib": ["dom", "esnext"],
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"preserveConstEnums": true,
"resolveJsonModule": true,
"sourceMap": true,
"removeComments": false,
"strict": true,
"strictNullChecks": true,
"importHelpers": true,
"suppressImplicitAnyIndexErrors": true,
"preserveWatchOutput": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"baseUrl": ".",
"paths": {
"packages/*": ["packages/*"]
}
},
"exclude": ["*node_modules", "**/*.test.ts*"]
}

这是/ui tsconfig:

{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"composite": true,
"noEmit": false,
"outDir": "build",
"rootDir": "src",
"lib": ["dom", "dom.iterable", "esnext"],
"isolatedModules": true,
"jsx": "react-jsx",
"allowJs": true,
"declaration": true,
"declarationMap": true,
"paths": {
"@/*": ["src/*"],
"@/config": ["src/config.ts"],
"@/components/*": ["src/components/*"],
"@/assets/*": ["src/assets/*"]
}
},
"types": [
"jest",
"@types/testing-library__react",
"@types/testing-library__jest-dom",
"node"
],
"references": [
{
"path": "../graphql"
}
],
"exclude": ["build"],
"include": ["src"]
}

一切似乎都井然有序,尤其是在使用VS代码时,因为在TypeScript功能方面一切都正常。

在/graphql repo上运行tsc --build不会出错(即使由于tsconfig而没有输出,也尝试添加outFile,但没有成功(。

但是,当我在/ui包上运行tsc --buildtsc -p tsconfig.json时,我会收到以下错误:

Could not find a declaration file for module '@goe/graphql'. '[...]/packages/frontend/graphql/build/index.js' implicitly has an 'any' type.

我做错了什么?

似乎我在阅读我的问题时偶然发现了解决方案,错误的一部分说index.js的类型是any,这可能让我觉得我只需要发出具有相同名称的类型,所以我只是将graphql-tsconfig改为

{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"composite": true,
"jsx": "react",
"declaration": true, // this option alone to emit types next to each compiled file
"noEmit": false,
"outDir": "build",
"rootDir": "src"
},
"include": ["**/*.tsx", "**/*.ts"],
"exclude": ["build"]
}

现在tsc构建在/ui上工作:(

相关内容

最新更新