-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript types adding unwanted / buggy 'Chai.Assertion' type requirement on should
function interface return
#2118
Comments
Technically this is expected behaviour, because Don't know what to do with this 🤷🏻 |
It was an interesting experience to debug, I had never heard of That is why I raised it as an issue as it was such an obscure bug (try searching it on google!) |
should
function interface returnshould
function interface return
I have a similar problem, the interface pollution by chai breaks compilation when I'm also using types from @elastic/elasticsearch, which also has an object with a should-property. Identical to this issue. It's been over a year since the chai-types module owners were pinged in the github discussion on this, without any reaction. I suggest finding a way to drop the @types/chai dependency from vitest, so I can choose for myself whether to include it or not. |
Additionally, I think it would be beneficial to have the two api's be (optionally) independent of one another. For example, I might want to limit my repo to only using the Jest API, therefore I wouldn't even want to be bother seeing the Chai API in my autocompletes. This would be a big improvement in helping young developers contribute tests, since they wouldn't have to muddle through questions like: Are these two the same? Which one is better? Which one is expected for this repo? expect(1).to.equal(1);
expect(1).toBe(1); |
This is the main issue preventing our team from adopting vitest. I also had a difficult time finding the error, and I'm very glad this issue exists. We have an absurd amount of OpenSearch Query objects in our code-base that look something like this: const queryBool = {
bool: {
should: [
{
term: { foo: "bar" }
}
]
}
} Even something like this errors: const query: OpenSearchBool["bool"] = {};
// Types of property 'should' are incompatible. And, of course, doing something like this is invalid: interface Object {
should?: any;
// All declarations of 'should' must have identical modifiers.
} We could start doing "bad things" to try and work around this issue, like adding a {
"scripts": {
"post-install": "rm node_modules/@types/chai/index.d.ts",
}
} But I feel like that is going down a dark path. Typescript does not currently have a way to exclude the types included by packages or isolate global interface pollutions like this, but the feature request has been hotly debated. This is especially an issue in the This is an extra-tough issue, since the offending types are in your dependency, and they likely will not be changing. You do, however have control over which dependencies you include in the main vitest package. I second the recommendation to remove the Until that happens, we'll have to go back to another testing environment, which (given the enthusiasm from the team) is disappointing. |
Glad this issue helps. Currently working with wonderful, pure Rust types. I don't miss typescript at all. |
@keithamus I am not sure who is responsible for |
FWIW this is the first I've heard of this.
Perhaps the types need to change such that the function should(): Object is Object & {should: Chai.Assertion} {} But I don't know if that's valid TS, or if it is, whether it is actually usable for users of the should syntax. |
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 typeAssertion
if it returns an object literalThis 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):
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: