Fix: Improve type safety in features/support/formatter_output_helpers, removes explicit any
#1648
#2558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤔 What's changed?
Modified several places where ESLint was complaining about the use of explicit
any
( after I set@typescript-eslint/no-explicit-any
to2
) in thefeatures/support/formatter_output_helpers.ts
file.There were multiple checks using
doesHaveValue
but unfortunately this does not assure the TypeScript compiler that it is safe to refer to properties of the value; e.g.let x = 2; if (doesHaveValue(x)) console.log(x.anything) // type error
so I had to add aisObject
check so that it would be safe to refer to properties of values. So the use ofdoesHaveValue
was replaced byisObject
in a few places. You may want to move theisObject
function to a shared file likesrc/value_checker
because it's not specifically tied to the file it is defined in.In other places I just replaced
any
with the correct type.⚡️ What's your motivation?
This will improve the type safety of the code base a tiny bit and help whittle down the list of files that break when the
@typescript-eslint/no-explicit-any
rule is enabled.🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
There are multiple ways that this issue could have been resolved; I tried to pick a solution that made the least changes to the existing code. You may have different priorities.
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.