Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Sep 30, 2022

This PR cleans up some of the types in jest.setup.ts.

@jsjoeio jsjoeio self-assigned this Sep 30, 2022
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using as 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]) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here logType is limited to the options we specify in CONSOLE_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 => {
Copy link
Contributor Author

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 use any.

@jsjoeio jsjoeio marked this pull request as ready for review September 30, 2022 22:10
@jsjoeio jsjoeio requested a review from a team as a code owner September 30, 2022 22:10
@jsjoeio jsjoeio requested review from Kira-Pilot and removed request for a team September 30, 2022 22:10
Copy link
Member

@Kira-Pilot Kira-Pilot left a 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.

@jsjoeio jsjoeio merged commit ce95344 into main Oct 4, 2022
@jsjoeio jsjoeio deleted the jsjoeio/eslint-cleanups branch October 4, 2022 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants