ts2339: property 'should' does not exist on type Bluebird<boolean>

Viewed 1773

I wrote my mocha test in Typescript, and now I'm compiling it in es6

tsc *.ts --target es6 -m commonjs --watch

I get NO error in the console,
But in the WebStorm I get underlined every 'should' chai-keyword with red (when I hover it I get a message: ts2339: property 'should' does not exist on type Bluebird).

for example I'm using 'chai' and I want to check is expected value true:

import * as chai    from "chai";

export class WrapedChai {
     public shouldBeTrue(valueToTest : any){
        let expectedValue : boolean = true;
        expectedValue.should.equal(valueToTest);
    }
// or usintg SHOULD with a Promise
     public belongsToGLOErrorPromise(valueToTest: any) {
        let expectedValue   : boolean = true;
        return Promise.resolve(expectedValue).should.eventually.equal(valueToTest);
    } 
}

and should is always underlined in red.

I tried this:

import { should } from 'chai';
should();

and this:

import chai = require('chai');
var should = chai.should();

but 'should' stil stays underlined as an error.

3 Answers

This can be solved with npm install @types/chai.

The current version of Chai no longer supports types different than 'any'.

So your suggestion to cast to 'any' is good.

Also the previous version before 4.2.0 still support all types, so using the previous version can solve it and use this with no issues:

let expectedValue : boolean = true;
expectedValue.should.equal(valueToTest);

https://github.com/chaijs/chai/issues/1100

Related