typescript - 使用 TypeScript 的 should.js 问题

标签 typescript should.js

我的代码是:

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

TypeScript 给我的错误是

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

那么如何将 should 与 TypeScript 一起使用呢?

最佳答案

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

我已经测试了这段代码并且它有效!如果我评论导入,我遇到了与您相同的问题。

import 'should';

describe('test', () => {

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

关于typescript - 使用 TypeScript 的 should.js 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50496982/

相关文章:

javascript - Superagent 'request' 对象被重新定义为函数?

javascript - Should.js:检查两个数组是否包含相同的字符串

javascript - 异步 Mocha 测试中出现超时错误

angular - 闪屏。 ( Angular 2)

reactjs - 设置 react-styleguidist、创建 React App、Typescript、Material UI 和 styled-components

reactjs - 在 typescript 中使用 defaultProps 的 forwardRef

typescript - 如何使用一组有效键中的任意键定义对象的类型?

javascript - Chrome DevTools 不显示 .js 文件

javascript - 使用 should.js 如何检查数组中是否不存在字符串?

javascript - 如何将 "callback pyramid"重构为基于 promise 的版本