- Notifications
You must be signed in to change notification settings - Fork928
refactor: clean up types in jest.setup.ts#4285
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@@ -38,16 +38,12 @@ afterAll(() => server.close()) | |||
// For now, I limited this to just 'error' - but failing on warnings | |||
// would be a nice next step! We may need to filter out some noise | |||
// from material-ui though. | |||
const CONSOLE_FAIL_TYPES = ["error" /* 'warn' */] | |||
const CONSOLE_FAIL_TYPES = ["error" /* 'warn' */] as const |
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.
Usingas const
narrows the type to string literals which is more correct.
const consoleAsAny = global.console as any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
consoleAsAny[logType] = (format: string, ...args: any[]): void => { | ||
CONSOLE_FAIL_TYPES.forEach((logType: typeof CONSOLE_FAIL_TYPES[number]) => { |
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.
herelogType
is limited to the options we specify inCONSOLE_FAIL_TYPES
.
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
consoleAsAny[logType] = (format: string, ...args: any[]): void => { | ||
CONSOLE_FAIL_TYPES.forEach((logType: typeof CONSOLE_FAIL_TYPES[number]) => { | ||
global.console[logType] = <Type>(format: string, ...args: Type[]): 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.
Using the generic, we no longer need to useany
.
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 job! Thanks for the comments.
Uh oh!
There was an error while loading.Please reload this page.
This PR cleans up some of the types in
jest.setup.ts
.