Skip to content

Typescript types adding unwanted / buggy 'Chai.Assertion' type requirement on should function interface return #2118

@ActuallyHappening

Description

@ActuallyHappening

Describe the bug

When this package is installed in a fresh vite project, a function that has a type annotation to return an interface (of anything, as long as it is not an empty interface) mysteriously requires that a returned object's should key be of type Assertion if it returns an object literal

This is a problem, even if it is intended behaviour because a larger project that contains a function anywhere (in typescript) generally suffers from this mysterious behaviour.
It was not immediately obvious that this typing behaviour was from this package, however it is clearly the source or is causing it, an issue with this repository.

This bug was initially found by refactoring large sections of typing after installing this library.
This library extends the Object interface to add should: Chai.Assertion, which was very annoying to identify and results in this package being uninstalled (as it was not being used at the time)

Reproduction

Exact file from repo,
git clone https://github.com/ActuallyHappening/messing-about.git

Code (from repo):

interface test {
  anything: "here";
  asLongAs: "there is at least one property";
  inThe: "interface";
}
function func(): test {
  return {
    should: "what is this `Assertion` type?", // Error here, copy-pasted below
    /*
    Type 'string' is not assignable to type 'Assertion'.ts(2322)
    index.d.ts(1940, 5): The expected type comes from property 'should' which is declared here on type 'test'
    */
  };
};

System Info

System:
    OS: macOS 12.6
    CPU: (8) arm64 Apple M2
    Memory: 108.75 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Brave Browser: 104.1.42.97
    Chrome: 105.0.5195.125
    Safari: 16.0

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions