Skip to content

[chai] Add proper AssertionError export#73830

Merged
typescript-bot merged 4 commits into
DefinitelyTyped:masterfrom
MysteryBlokHed:chai/add-assertionerror-export
Oct 20, 2025
Merged

[chai] Add proper AssertionError export#73830
typescript-bot merged 4 commits into
DefinitelyTyped:masterfrom
MysteryBlokHed:chai/add-assertionerror-export

Conversation

@MysteryBlokHed
Copy link
Copy Markdown
Contributor

Related discussion: #73706

If changing an existing definition:

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Oct 4, 2025

@MysteryBlokHed Thank you for submitting this PR!

This is a live comment that I will keep updated.

2 packages in this PR

Code Reviews

This PR can be merged once it's reviewed.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Type definition owners or DT maintainers needs to approve changes that affect more than one package

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 73830,
  "author": "MysteryBlokHed",
  "headCommitOid": "bd3ca47bef5c0d8705135ff3aa77bcf14ecf3d37",
  "mergeBaseOid": "1bd98ac5bc0736394b19b16dacd2e8626a170b3c",
  "lastPushDate": "2025-10-04T00:18:16.000Z",
  "lastActivityDate": "2025-10-20T23:14:58.000Z",
  "maintainerBlessed": "Waiting for Author to Merge (Blessed)",
  "mergeOfferDate": "2025-10-20T22:43:24.000Z",
  "mergeRequestDate": "2025-10-20T23:14:58.000Z",
  "mergeRequestUser": "MysteryBlokHed",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "bardjs",
      "kind": "edit",
      "files": [
        {
          "path": "types/bardjs/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "chai",
      "kind": "edit",
      "files": [
        {
          "path": "types/chai/chai-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/chai/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/chai/package.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "Bartvds",
        "AGBrown",
        "olivr70",
        "mwistrand",
        "shaunluttin",
        "micksatana",
        "ErikSchierboom",
        "bparan",
        "CXuesong",
        "joeykilpatrick"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2025-10-20T22:42:14.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 3367605516,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @Bartvds @AGBrown @olivr70 @mwistrand @shaunluttin @micksatana @ErikSchierboom @bparan @CXuesong @joeykilpatrick — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Oct 4, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in Pull Request Status Board Oct 4, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@MysteryBlokHed The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed The CI failed When GH Actions fails Untested Change This PR does not touch tests labels Oct 4, 2025
@MysteryBlokHed MysteryBlokHed force-pushed the chai/add-assertionerror-export branch from 38eced0 to 62586c4 Compare October 4, 2025 00:27
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Oct 4, 2025
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Oct 4, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@MysteryBlokHed The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in Pull Request Status Board Oct 4, 2025
@MysteryBlokHed MysteryBlokHed force-pushed the chai/add-assertionerror-export branch from 62586c4 to 8584478 Compare October 4, 2025 05:00
@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Oct 4, 2025
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Oct 4, 2025
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Oct 4, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in Pull Request Status Board Oct 4, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@MysteryBlokHed The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

@MysteryBlokHed MysteryBlokHed force-pushed the chai/add-assertionerror-export branch from 8584478 to 3343cfd Compare October 4, 2025 05:08
@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Oct 4, 2025
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Oct 4, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Oct 4, 2025
@MysteryBlokHed MysteryBlokHed force-pushed the chai/add-assertionerror-export branch from 3343cfd to 4f06bed Compare October 4, 2025 05:14
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in Pull Request Status Board Oct 4, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Oct 4, 2025
Comment thread types/chai/index.d.ts Outdated
showDiff: boolean;
stack: string;
}
export type AssertionError = typeof ImportedAssertionError;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just a plain reexport?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't seem to be able to re-export it like this (when importing as import { AssertionError } from "assertion-error"), since it caused type errors elsewhere:

        export { AssertionError };

Which is why I wrote it the way I did.

This Chai namespace also doesn't seem to exist at runtime, and it only defines types; everything other than this AssertionError class is an interface or type alias. So just exporting the type of AssertionError seemed to make sense to me

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The errors would be helpful to look at, though it is interesting that this is used for the type only namespace, but you noted that the real package depended on it. I do wonder how these types are intended to be used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The class is also re-exported by the chai library and available at runtime, which I've represented in the types:

export const AssertionError: typeof ImportedAssertionError;

I also updated the type in the Chai namespace, but that wasn't the main purpose of the PR. The original discussion was specifically about the type definitions not indicating that AssertionError is directly exported by chai: #73706

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, for reference, here are the errors I get from pnpm test chai if I try to change the way I export the type in the namespace:

--- a/types/chai/index.d.ts
+++ b/types/chai/index.d.ts
@@ -2129,7 +2129,7 @@ declare global {
             deepEqual: <L, R>(expected: L, actual: R) => void;
         }
 
-        export type AssertionError = typeof ImportedAssertionError;
+        export { ImportedAssertionError as AssertionError };
     }
 }
 
$ pnpm test chai

> definitely-typed@0.0.3 test /home/adam/Git/DefinitelyTyped
> node --enable-source-maps node_modules/@definitelytyped/dtslint/ types "chai"

dtslint@0.2.34
Error:
/home/adam/Git/DefinitelyTyped/types/chai/chai-tests.ts
   783:36  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiStatic'                     @definitelytyped/expect
   783:60  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiUtils'                      @definitelytyped/expect
   788:39  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'this' implicitly has type 'any' because it does not have a type annotation     @definitelytyped/expect
   792:17  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'this' implicitly has type 'any' because it does not have a type annotation     @definitelytyped/expect
   803:39  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'this' implicitly has type 'any' because it does not have a type annotation     @definitelytyped/expect
   807:17  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'this' implicitly has type 'any' because it does not have a type annotation     @definitelytyped/expect
   818:51  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'global.Chai' has no exported member named 'Assertion'. Did you mean 'Assert'?  @definitelytyped/expect
   878:52  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiStatic'                     @definitelytyped/expect
   878:76  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiUtils'                      @definitelytyped/expect
   882:13  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
'this' implicitly has type 'any' because it does not have a type annotation     @definitelytyped/expect
  2236:26  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Parameter 'expected' implicitly has an 'any' type                               @definitelytyped/expect
  2236:36  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Parameter 'actual' implicitly has an 'any' type                                 @definitelytyped/expect

/home/adam/Git/DefinitelyTyped/types/chai/index.d.ts
  2136:30  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiPlugin'  @definitelytyped/expect
  2136:48  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiStatic'  @definitelytyped/expect
  2138:25  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'ChaiUtils'   @definitelytyped/expect
  2142:32  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'Should'      @definitelytyped/expect
  2143:32  error  TypeScript@5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 compile error:
Namespace 'global.Chai' has no exported member 'Should'      @definitelytyped/expect

✖ 17 problems (17 errors, 0 warnings)

    at combineErrorsAndWarnings (/home/adam/Git/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.34_typescript@6.0.0-dev.20251003/node_modules/@definitelytyped/dtslint/src/index.ts:266:26)
    at runTests (/home/adam/Git/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.34_typescript@6.0.0-dev.20251003/node_modules/@definitelytyped/dtslint/src/index.ts:257:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async main (/home/adam/Git/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.34_typescript@6.0.0-dev.20251003/node_modules/@definitelytyped/dtslint/src/index.ts:103:22)
 ELIFECYCLE  Test failed. See above for more details.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, adding export {} in a dts file disables implicit exports; if you explicitly add export to all of the types and such in the namespace, that would fix things.

I'm pretty sure this hasn't been caught because chai for some reason has disabled the eslint rule that notes when an export modifier doesn't mean anything.

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh right, I forgot about that

I've added an explicit export to each of the interfaces and types. I also used export type {} for AssertionError instead of just export {}, since the Chai namespace doesn't exist at runtime

`export type {}` was used for `AssertionError` since the `Chai` namespace
doesn't actually exist at runtime.
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in Pull Request Status Board Oct 13, 2025
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Oct 13, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in Pull Request Status Board Oct 13, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@MysteryBlokHed The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot added Edits multiple packages and removed The CI failed When GH Actions fails labels Oct 13, 2025
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Oct 13, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Oct 13, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@jakebailey Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Oct 15, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

Re-ping @Bartvds, @AGBrown, @olivr70, @mwistrand, @shaunluttin, @micksatana, @ErikSchierboom, @bparan, @CXuesong, @joeykilpatrick:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

@sheetalkamat sheetalkamat moved this from Needs Maintainer Review to Waiting for Code Reviews (Blessed) in Pull Request Status Board Oct 15, 2025
@jakebailey
Copy link
Copy Markdown
Member

Let's see how this goes...

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Oct 20, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews (Blessed) to Waiting for Author to Merge (Blessed) in Pull Request Status Board Oct 20, 2025
@typescript-bot
Copy link
Copy Markdown
Contributor

@MysteryBlokHed: Everything looks good here. I am ready to merge this PR (at bd3ca47) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

@MysteryBlokHed
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge (Blessed) to Recently Merged in Pull Request Status Board Oct 20, 2025
@typescript-bot typescript-bot merged commit df5fcaf into DefinitelyTyped:master Oct 20, 2025
4 checks passed
@MysteryBlokHed MysteryBlokHed deleted the chai/add-assertionerror-export branch October 20, 2025 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Edits multiple packages Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants