-
-
Notifications
You must be signed in to change notification settings - Fork 3k
chore: move callback and object typedefs to a new types.d.ts #5351
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
base: main
Are you sure you want to change the base?
Conversation
Why everything in one large Also: You can try to use (still sometimes buggy) the /** @import { Foo } from './bar.js' */ |
I don't have preferences on where to organize types, since this feels like a transient "we'll clean things up over time anyway" kind of situation to me 😄. Do you have a preference for where things should go? |
ping @voxpelli did you mean for #5351 (comment) to be a full review? I'm not clear on whether you're requesting changes and waiting on me, or just posting thoughts pending a full review? |
@JoshuaKGoldberg Posting thoughts pending a full review, thanks for pinging and asking 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good, requested a few changes :)
/** Disable syntax highlighting? */ | ||
noHighlighting?: boolean; | ||
|
||
/** - Reporter name or constructor. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** - Reporter name or constructor. */ | |
/** Reporter name or constructor. */ |
/** Number of times to retry failed tests. */ | ||
retries?: number; | ||
|
||
/** Slow threshold value. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Slow threshold value. */ | |
/** Slow threshold value, in milliseconds. */ |
/** Slow threshold value. */ | ||
slow?: number; | ||
|
||
/** Timeout threshold value. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Timeout threshold value. */ | |
/** Timeout threshold value, in milliseconds. */ |
* @private | ||
* @param failures - Number of failures that occurred. | ||
*/ | ||
export type DoneCB = (failures: number) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know in JS all params are implicitly optional, but I think we should be explicit for clarity
export type DoneCB = (failures: number) => void; | |
export type DoneCB = (failures?: number) => void; |
* Diagnostic object containing unmatched files | ||
*/ | ||
export interface UnmatchedFile { | ||
/** A list of unmatched files derived from the file arguments passed in */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List? How are entries separated? Or should this be an array? Same for next entry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comments for this UnmatchedFile type were copy-pasted wrong :)
@@ -163,6 +168,7 @@ | |||
"rollup-plugin-polyfill-node": "^0.8.0", | |||
"rollup-plugin-visualizer": "^5.6.0", | |||
"sinon": "^9.0.3", | |||
"typescript": "^5.8.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS famously doesn't follow semantic versioning, but I believe they only introducing breaking changes in minor versions, never in patches
"typescript": "^5.8.3", | |
"typescript": "~5.8.3", |
@@ -1,6 +1,7 @@ | |||
'use strict'; | |||
|
|||
var errors = require('../../lib/errors'); | |||
var constants = require('../../lib/error-constants'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are adding a reference to error-constants, can we remove the references to errors
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR centralizes JSDoc type definitions into a new lib/types.d.ts
, moves error constants to lib/error-constants.js
, and updates module files to import those typedefs. It also adds a tsconfig.json
and GitHub Actions job to run tsc
for type checking.
- Consolidated all
@callback
/@typedef
declarations intotypes.d.ts
- Extracted error constants into
lib/error-constants.js
and updated imports - Added a
tsc
script and workflow step for validating the new types
Reviewed Changes
Copilot reviewed 47 out of 47 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
lib/reporters/base.js | Removed inline FullErrorStack typedef and added import from types.d.ts |
lib/plugin-loader.js | Removed inline PluginDefinition and PluginLoaderOptions typedefs, added imports |
lib/nodejs/worker.js | Removed inline BufferedEvent /MochaOptions typedefs, added imports and updated @param |
lib/nodejs/serializer.js | Removed inline SerializedEvent /SerializedWorkerResult typedefs, added imports |
lib/nodejs/reporters/parallel-buffered.js | Removed inline BufferedEvent typedef and added import |
lib/nodejs/parallel-buffered-runner.js | Removed inline SigIntListener /FileRunner typedefs, added imports |
lib/nodejs/buffered-worker-pool.js | Removed inline typedefs, added imports for WorkerPoolOptions , MochaOptions , results |
lib/mocha.js | Removed many inline typedefs, added imports for DoneCB , fixtures, options, reporter types |
lib/interfaces/tdd.js | Added Suite typedef import |
lib/interfaces/qunit.js | Added Suite typedef import |
lib/interfaces/common.js | Added Context and Mocha typedef imports |
lib/interfaces/bdd.js | Added Suite typedef import |
lib/errors.js | Removed inline constants, imported from error-constants.js , no longer exports constants |
lib/error-constants.js | New file exporting all Mocha error constants |
lib/context.js | Added Runnable typedef import |
lib/cli/watch-run.js | Added typedef imports for FSWatcher , Mocha , BeforeWatchRun , FileCollectionOptions , etc. |
lib/cli/run-option-metadata.js | Updated JSDoc {{string:string[]}} to Record<string,string[]> |
lib/cli/run-helpers.js | Added imports for Mocha , MochaOptions , UnmatchedFile , Runner |
lib/cli/collect-files.js | Switched error import to error-constants , added FileCollectionOptions /Response imports |
.github/workflows/mocha.yml | Added tsc job to run the TypeScript compiler for validation |
Comments suppressed due to low confidence (2)
lib/errors.js:418
- The
constants
object was removed from this module’s exports but is still documented undermodule:lib/errors
. If backward compatibility is required, re-exportconstants
here or update documentation to reflect the new location.
module.exports = {
lib/error-constants.js:4
- The
@memberof module:lib/errors
tag is misleading in this standalone file. Consider changing it tomodule:lib/error-constants
or removing the@memberof
directive.
* @memberof module:lib/errors
PR Checklist
status: accepting prs
Overview
Creates a new
lib/types.d.ts
and moves every@callback
and@typedef {Object}
to it. A newtsconfig.json
&tsc
script can be run to verify that the types in that file can be type checked.Does not yet validate types in
.js
files (#4154, #4228). You can preview those by switchingtsconfig.json
'sallowJs
tocheckJs
. I made sure there are no more "Cannot find name ...
" errors but fixing the rest of the ~650+ will be a lot more work. Much of the code will be much easier to get type-safe when it's ported from manual function prototypes to classes (#5025). I also held off porting all the info from@types/mocha
there to keep the changes minimal.Does not yet try to pull in types or descriptions from
@types/mocha
. That would be a bigger change too.Moves error constants from
errors.js
toerror-constants.js
to avoid circular dependency errors.