ref(types): add default type parameters for RouteComponentProps #85139
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.
giving the type RouteComponentProps safe default values for
Params
andRouteParams
avoids us having to always pass them where we don't know / don't want to restrict us to specific params, which is the case in many places. Oftentimes, the type{}
was used, which is an unsafe type that we're trying to get rid of and forbid its usage with eslintWith those changes, this PR gets the usages of the empty object type down to 275 from the initial starting point of 465.
The most relevant changes are:
Record<string, string | undefined>
is a “safe” default value, as it means all params that components get access to from the router can be read in a potentially undefined way.Usages where we know parameters exist because of route matching can still overwrite this default, which is what we frequently do, e.g.:
In this cases,
orgId
can be read as type string, and it will also be the only key that can be read fromparams
.some other interfaces had to be widened per default from
Record<string, string>
toRecord<string, string | undefined>
so that they are compatible:This change didn’t yield any type errors, but it will make future access more safe.