Skip to content

no-class-in-interface

✅ Using recommended in an ESLint configuration enables this rule.

This rule disallows using class types in interface properties.

When class types are used in interface properties, it creates tight coupling between the interface and the class implementation.
Additionally, classes are mutable by nature, which can lead to unexpected behavior when used as interface property types.
So not good.

✅ Correct Example

ts
import { IBucket } from "aws-cdk-lib/aws-s3";

interface MyConstructProps {
  // ✅ Can use an interface
  readonly bucket: IBucket;
}

❌ Incorrect Example

ts
import { Bucket } from "aws-cdk-lib/aws-s3";

interface MyConstructProps {
  // ❌ Shouldn't use a class
  readonly bucket: Bucket;
}