You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That means if you want to describe any arbitrary rule context the way e.g. #8146 does, you have to explicitly type out RuleContext<string, unknown[]>. It's a little inconvenient.
Proposal: let's add defaults to make referring to an "unknown" rule context a little easier?
I think it's fine to not provide defaults because it means that you have to specifically opt-in to the unbounded, unsafe behaviour.
This is good because it means that if someone is writing a rule and wants to pass the context around they have to pass the parameters - preventing unsafe code.
For example this is a very common pattern I've seen:
You might say "but if they move the function into the create body they could remove the param entirely!" and you're not wrong - but who are we to dictate others preferred style?
If we default the type params then it's valid for the user to define context: RuleContext for said function - which means that when that function calls eg contex.report it will have zero safety around the message ids!
I'd much rather export an obviously unsafe version of the type like we do for the RuleModule
Before You File a Proposal Please Confirm You Have Done The Following...
Relevant Package
utils
My proposal is suitable for this project
Description
Right now,
RuleContext
doesn't provide defaults for its type parameters:typescript-eslint/packages/utils/src/ts-eslint/Rule.ts
Lines 175 to 178 in 99a026f
That means if you want to describe any arbitrary rule context the way e.g. #8146 does, you have to explicitly type out
RuleContext<string, unknown[]>
. It's a little inconvenient.Proposal: let's add defaults to make referring to an "unknown" rule context a little easier?
Additional Info
#8148 is a draft PR showing the changes internally.
The text was updated successfully, but these errors were encountered: