[chai] Add proper AssertionError export#73830
Conversation
|
@MysteryBlokHed Thank you for submitting this PR! This is a live comment that I will keep updated. 2 packages in this PRCode ReviewsThis PR can be merged once it's reviewed. You can test the changes of this PR in the Playground. Status
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"
} |
|
🔔 @Bartvds @AGBrown @olivr70 @mwistrand @shaunluttin @micksatana @ErikSchierboom @bparan @CXuesong @joeykilpatrick — please review this PR in the next few days. Be sure to explicitly select |
|
@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. |
38eced0 to
62586c4
Compare
|
@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. |
62586c4 to
8584478
Compare
|
@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. |
8584478 to
3343cfd
Compare
3343cfd to
4f06bed
Compare
| showDiff: boolean; | ||
| stack: string; | ||
| } | ||
| export type AssertionError = typeof ImportedAssertionError; |
There was a problem hiding this comment.
Why not just a plain reexport?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
|
@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. |
|
@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? |
|
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! |
|
Let's see how this goes... |
|
@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:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ |
|
Ready to merge |
Related discussion: #73706
pnpm test <package to test>.If changing an existing definition:
package.json.