【问题标题】:Issue with should.js using TypeScript使用 TypeScript 的 should.js 问题
【发布时间】:2018-11-02 22:50:16
【问题描述】:

我的代码是:

Object.keys(res.body.data).should.containEql('id')

TypeScript 给我的错误是

Property 'should' does not exist on type 'string[]'.

那么我如何在 TypeScript 中使用should

【问题讨论】:

  • 如果我的回答解决了您的问题,请告诉我!

标签: typescript should.js


【解决方案1】:

您缺少 should 库的导入。基本上你需要导入 import 'should' 才能访问 should 方法。

我已经测试了这段代码,它可以工作!如果我评论导入,我会遇到与您相同的问题。

import 'should';

describe('test', () => {

    it('should must work', () => {
        Object.keys({ a: 1, b: 2 }).should.containEql('b');
    })
})

【讨论】:

  • 这不能为我编译(TypeScript 2.9.2)。
  • 您是否安装了定义? npm install @types/should @types/mocha --save-dev
  • 啊,我没有意识到这是在 Mocha 下运行的。现在它起作用了。不错!
猜你喜欢
  • 2019-11-21
  • 2021-10-03
  • 2016-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多