-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
chore(jest-resolve): improve types #10239
Conversation
@@ -31,11 +31,11 @@ export default class ModuleNotFoundError extends Error { | |||
|
|||
let message = this._originalMessage; | |||
|
|||
if (this?.requireStack?.length && this!.requireStack!.length > 1) { | |||
if (this.requireStack?.length && this.requireStack.length > 1) { |
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.
👍
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 (this.requireStack?.length && this.requireStack.length > 1) { | |
if (this.requireStack?.length > 1) { |
?
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.
>
requires both sides to be a number, so you can't do undefined > 1
in TS - I thought about merging these but decided against it as I think the alternatives don't really add much while not being as clean, i.e (this.requireStack?.length ?? 0) > 1
@@ -21,11 +21,19 @@ type ResolverOptions = { | |||
rootDir?: Config.Path; | |||
}; | |||
|
|||
declare global { |
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.
nice solution
namespace NodeJS { | ||
export interface Process { | ||
// "private" api | ||
binding(type: string): {}; |
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.
won't this pollute the global definition of all consumers as well? I'm down with adding pnp
as optional, but this one is purposefully not added to global types by DT and is highly discouraged to use by Node itself
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.
Yeah I realised this after I pushed. I'll restore the declare and just add & process
.
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.
fwiw this should be "fine" as it only takes effect when this file is imported, which none of the d.ts
s do since it's not a public function, but I'll change it for peace of mind all the same.
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.
Left some q's, this is great, thanks!
Thanks! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Improves the types of
jest-resolve
mainly for #10177, and also cleaning up a few little nits around the place, including a nice little find inModuleNotFoundError
.Test plan
Run the tests and see if anything breaks 🚂