#1314·chai

Typescript test says error TS2339: Property 'by' does not exist on type 'Assertion'.

Author: crystalfpCreated Jan 10, 2020Updated Sep 5, 2026

I'm trying to test if an array increases in length by 1 after executing a certain operation. The test is written in typescript and runs with the usual mocha -r ts-node/register mytest.ts. The chai version is 4.2.0. Unfortunately, it does not compile with the error: TS2339: Property 'by' does not exist on type 'Assertion'. Here is a simplified test to reproduce the error:

import {expect} from "chai";

describe("OneTest", function() {
	it("bugz", function(done) {

		const aa = [1, 2, 3];

		const len = aa.length;

		expect(aa.push(88)).to.increase({len}, "len").by(1);

		done();
	});
});

I don't see any definition for by() in @types/chai file index.d.ts and if I add the line by(delta: number): Assertion; at the end of interface Assertion it compiles. Well, the test fails, but this is another problem.

Thanks for investigating! mario