typescriptshould.js

Issue with should.js using TypeScript


My code is:

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

The error that TypeScript gives me is

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

So how do I use should with TypeScript?


Solution

  • You are missing the import of should library. Basically you need to import import 'should' to have access to should methods.

    I have tested this code and it works! If I comment the import I had the same issue that you have.

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