微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

类型 'import("c......./node_modules/@types/express/index").Application' 不可分配给类型

如何解决类型 'import("c......./node_modules/@types/express/index").Application' 不可分配给类型

我遇到了这个打字稿问题,我不明白它背后的原因是什么

这也不起作用

import { IResolvers } from 'apollo-server-express';
import { listings } from '../listings';

模块“apollo-server-express”没有导出成员“IResolvers”

import express,{ Application } from "express";
import { ApolloServer } from "apollo-server-express";
import { connectDatabase } from "./database";
import { typeDefs,resolvers } from "./graphql";

const port = 9000;
                  
const mount = async (app: Application) => {
  const db = await connectDatabase();
  const server = new ApolloServer({
    typeDefs,resolvers,context: () => ({ db })
  });
                         // error message is produced here
  server.applyMiddleware({ app,path: "/api" });
  app.listen(port);

  console.log(`[app] : http://localhost:${port}`);

  const listings = await db.listings.find({}).toArray();
  console.log(listings);
};

mount(express());

类型'import("c:/Users/User/Desktop/lesson_4.4/source_code/server/node_modules/@types/express/index").Application'不可分配给类型'import("c:/用户/用户/桌面/lesson_4.4/source_code/server/node_modules/apollo-server-express/node_modules/@types/express/index").Application'。 属性“引擎”的类型不兼容。 类型 '(ext: string,fn: (path: string,options: object,callback: (e: any,render: string) => void) => void) => Application' 不能分配给类型 '(ext: string,render?: string | undefined) => void) => void) => Application'. 参数“fn”和“fn”的类型不兼容。 参数“回调”和“回调”的类型不兼容。 类型 '(e: any,render: string) => void' 不能分配给类型 '(e: any,render?: string | undefined) => void'。 'rendered' 和 'rendered' 的参数类型不兼容。 输入'字符串| undefined' 不能分配给类型 'string'。 类型 'undefined' 不可分配给类型 'string'.ts(2322) ApolloServer.d.ts(14,5):预期的类型来自属性“app”,该属性在此处声明为“ServerRegistration”

tsConfig

    {
  "compilerOptions": {
    "target": "es6","module": "commonjs","rootDir": "./src","outDir": "./build","esModuleInterop": true,"strict": true
  }
}

eslitConfig

  {
      "parser": "@typescript-eslint/parser","parserOptions": {
        "ecmaVersion": 2018,"sourceType": "module"
      },"extends": ["plugin:@typescript-eslint/recommended"],"env": { "node": true },"rules": {
        "indent": "off","@typescript-eslint/indent": "off","@typescript-eslint/explicit-function-return-type": "off"
      }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。