Skip to content

fix(types): ensure Chai declaration merge works with TS-Go #8188

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

LukeAbby
Copy link
Contributor

Description

Context: Currently TypeScript accepts code like this:

interface Foo {
    foo(x: any): void;
    foo: (x: any) => void;
}

While it does not accept code like this:

interface Foo {
    foo: (x: any) => void;
    foo(x: any): void;
}

The only difference being the ordering.

By comparison, in TypeScript Go neither of these are accepted. See microsoft/typescript-go#1192 (comment) for official confirmation by Anders Hejlsberg (lead architect of TypeScript). I noticed this effected Vitest due to its merge of Chai.Assert.containSubset as a callback instead of as a method, leading to a conflict with @types/chai.

No associated issue because it's a small types-only fix.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jun 19, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c0a2a03
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68541c9d717bf20008482608
😎 Deploy Preview https://deploy-preview-8188--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +10 to 16
interface ContainSubset {
(expected: any): Assertion
}

interface Assertion {
containSubset: (expected: any) => Assertion
containSubset: ContainSubset
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not critically necessary for supporting TS-Go. However while touching this area of the code I noticed that @types/chai does this:

        interface ContainSubset {
            (expected: any): Assertion;
        }

        interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
            ...
            containSubset: ContainSubset;
            ...
        }

And this change makes the polyfill here more compliant with what @types/chai is doing. Currently if someone changed ContainSubset it would break vitest.

Comment on lines +19 to +20
// eslint-disable-next-line ts/method-signature-style
containSubset(val: any, exp: any, msg?: string): void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change that's critical for TS-Go. You can test this locally by running these commands in packages/vitest:

pnpm add -D @typescript/native-preview
pnpm exec tsgo

Before this change you would get these errors:

src/types/global.ts:20:7 - error TS2300: Duplicate identifier 'containSubset'.

20       containSubset: (val: any, exp: any, msg?: string) => void
         ~~~~~~~~~~~~~

  ../../node_modules/.pnpm/@[email protected]/node_modules/@types/chai/index.d.ts:538:13 - 'containSubset' was also declared here.
    538             containSubset(val: any, exp: any, msg?: string): void;

After, these errors go away.

@LukeAbby
Copy link
Contributor Author

Could I get a rerun on "Browsers: node-20, macos-latest" and "Build&Test: node-20, windows-latest"?
The macos error is:

Error: Command failed: "/Applications/Firefox.app/Contents/MacOS/Firefox" --version

The windows error is:

@vitest/test-coverage : test test\coverage-test
  test/coverage-test test$ vitest --workspace=vitest.workspace.custom.ts
   ELIFECYCLE  Command failed with exit code 134.

I don't see how either of these could be caused by this change and I see these checks failing elsewhere.

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sheremet-va sheremet-va merged commit 5261df0 into vitest-dev:main Jun 20, 2025
13 of 15 checks passed
@LukeAbby LukeAbby deleted the chaiDeclarationMergeFix branch June 20, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants