no-empty-interface

Try in Playground
typescript-best-practicesError ProneWarning

1

No tags

No CWE or CVE

An empty interface is equivalent to an empty object ({}).

Normally you cannot directly assign an object literal to a type when the object literal contains more properties than are specified in the type. But in the case of an empty interface, this check is not done, and such assignments will be successful. The result is highly likely to confuse maintainers.

Ast Rule: interface


no-empty-interface

How to write a rule
function visit(node, filename, code) {
	if(node.members.length === 0) {
		const error = buildError(
			node.start.line,
			node.start.col,
			node.end.line,
			node.end.col,
			`An empty interface is equivalent to "{}"`,
			"WARNING",
			"ERROR_PRONE"
		);
		
		addError(error);
	}
}

empty.ts

Expected test result: has error

interface Person {}

not-empty.ts

Expected test result: no error

interface Person {
	name: string;
}  
Add comment

Log in to add a comment


    1 Comment

  • 0

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
Legal
  • Security
  • Privacy Policy
  • Code Privacy
  • Terms of Service
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.