【发布时间】:2018-12-09 08:48:23
【问题描述】:
除非我删除 noImplicitAny,否则我无法编译 typescript
我得到了这个错误,我正在使用来自 npm 的 merge-graphql-schemas 库
TSError: ⨯ Unable to compile TypeScript:
src/utils/genSchema.ts(1,44): error TS7016: Could not find a declaration file for module 'merge-graphql-schemas'. '/home/user/Documents/voting/node_modules/merge-graphql-schemas/dist/index.cjs.js' implicitly has an 'any' type.
Try `npm install @types/merge-graphql-schemas` if it exists or add a new declaration (.d.ts) file containing `declare module 'merge-graphql-schemas';
在我的 src->types->merge-graphql-schemas.d.ts
声明模块“merge-graphql-schemas”;
我的 tsconfig 是这样的
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"exclude": ["node_modules"],
"include": ["./src/**/*.tsx", "./src/**/*.ts"]
}
我是不是应该专门做点什么? 我将 lib 从 npm 更改为 schemaglue,即使它也没有类型,所以我做了同样的事情,但对于 schemaglue,我仍然得到相同的错误。 也许我在 tsconfig 中遗漏了什么?
这就是我使用 merge-schema-graphql 的原因
import { mergeTypes, mergeResolvers } from "merge-graphql-schemas";
import * as path from "path";
import * as fs from "fs";
import { makeExecutableSchema } from "graphql-tools";
import * as glob from "glob";
export const genSchema = () => {
const pathToModules = path.join(__dirname, "../modules");
const graphqlTypes = glob
.sync(`${pathToModules}/**/*.graphql`)
.map(x => fs.readFileSync(x, { encoding: "utf8" }));
const resolvers = glob
.sync(`${pathToModules}/**/resolvers.?s`)
.map(resolver => require(resolver).resolvers);
return makeExecutableSchema({
typeDefs: mergeTypes(graphqlTypes),
resolvers: mergeResolvers(resolvers)
});
};
礼貌 Youtube Benawad graphql-ts-server-boilerplate
【问题讨论】:
标签: typescript graphql