Rule proposal: Prefer a named interface or type over inline object literals #8320
Closed
6 tasks done
Labels
enhancement: new plugin rule
New rule request for eslint-plugin
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
wontfix
This will not be worked on
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
Sometimes folks write inline object type literals to represent objects in type annotations. For example, function parameters; return types; variable declarations. Two problems I see with these inline object literals:
Proposal: let's have a rule that bans object type literals in type annotations, with a configurable minimum number of object properties to report on? Let's say, banning types with >= 2 properties by default?
Fail Cases
Pass Cases
Additional Info
I'm not sure what the exact list of syntax locations should be. But "all type annotations" feels like a good start to me.
For auto-fixing, I can imagine this being useful in JSX-oriented libraries such as React if the auto-fixer creates a type with a name like
{Component}Props
when the type annotation is the first argument of a function that can be a JSX component.The text was updated successfully, but these errors were encountered: