Definitelytyped: chai definitions break tsx

Created on 26 Apr 2016  路  5Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [X] I tried using the latest chai/chai.d.ts file in this repo and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [X] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [X] I want to talk about chai/chai.d.ts.

    • The authors of that type definition are cc/ @Bartvds

The bit at the end of chai.d.ts:

interface Object {
    should: Chai.Assertion;
}

breaks tsx support because it thinks that all objects must have a should property (specifically, " Property 'should' is missing in type 'IntrinsicAttributes & IntrinsicClassAttributes

interface Object {
    should?: Chai.Assertion;
}

Most helpful comment

This Object interface expansion also cause another bug. Typescript compiler adds
/// <reference types="chai"> to all d.ts generated based on sources containing Object. (E.g. https://github.com/angular-redux/ng2-redux/pull/209/files)
I think it is better to eliminate polution Object interface with should property and make separate version of typings for those who need should assertion syntax.

All 5 comments

This Object interface expansion also cause another bug. Typescript compiler adds
/// <reference types="chai"> to all d.ts generated based on sources containing Object. (E.g. https://github.com/angular-redux/ng2-redux/pull/209/files)
I think it is better to eliminate polution Object interface with should property and make separate version of typings for those who need should assertion syntax.

It also breaks my compilation process because I have typings for Elasticsearch Search body requests. It has an internal interface

export interface Bool {
  should?: Query | Query[];
  filter?: Query | Query[];
  must?: Query | Query[];
  must_not?: Query | Query[];
}

And when I try to build an object with

const b: Bool = { should: query }

I get a type error saying that Query and Assertion are incompatible.

I agree with @nikolaymatrosov that we should not pollute the Object interface by default and I'm going to make a PR removing that last bit.

I couldn't manage a feasible PR because I tried to make it happen in the existing @types/chai package, but now I think we should instead create an alternatives types library that is exactly the same but doesn't contain the Object declaration.

Was this page helpful?
0 / 5 - 0 ratings