TypeScript不';无法识别supertest请求响应中的对象?
我正在使用Supertest为TypeScript中非常简单的GraphQLAPI编写一个测试。我收到以下错误:TypeScript不';无法识别supertest请求响应中的对象?,typescript,supertest,Typescript,Supertest,我正在使用Supertest为TypeScript中非常简单的GraphQLAPI编写一个测试。我收到以下错误:类型“Response”上不存在属性“data”,为什么要这样做?我还没告诉它那里会发生什么。但是我怎么能呢数据紧接着是应该 这是我的简短测试文件 import chai from "chai"; import { expect } from "chai"; import * as request from "supertest"; import app from "../src";
类型“Response”上不存在属性“data”
,为什么要这样做?我还没告诉它那里会发生什么。但是我怎么能呢数据紧接着是应该
这是我的简短测试文件
import chai from "chai";
import { expect } from "chai";
import * as request from "supertest";
import app from "../src";
describe("graphQl test", () => {
it("should respond with hello world", async (done) => {
const returned = await request(app)
.post("/graphql")
.send({ query: "{ hello }"})
.expect(200)
.end((err, res) => {
if (err) { return done(err); }
res.data.should.have.property("hello");
done();
});
expect(returned.data.hello).equal("Hello world!");
});
});
有没有简单的解决办法?如果不是,我想我必须创建某种类型的接口,但是在这个场景中,我如何创建一个接口并将该接口与TypeScript通信呢?我正在搜索,但还没有看到这方面的示例。您只需添加supertest类型,这样编译器就知道会发生什么 可以这样做:
npm install --save @types/supertest
我所有的打字机都安装好了。在这种情况下,我认为问题在让Mocha使用
ts节点的过程中得到了解决ts节点
无法与我的全局typescript
一起工作,因此我必须在本地安装它。然后我需要为我的测试添加一个单独的tsconfig.json
文件,VSCode停止给我这些错误,编译工作正常。返回的也可以是错误返回完成(err)代码>