class-syntax
a class whose constructor takes positional arguments, or whose methods declare separate param interfaces
Agent checkadvisory by defaultbasecode
The argument
Syntax & Style
- Constructor takes an object argument, destructured; declare a
ConstructorParamsinterface for it. - Instance methods use inline object types for their params — not separate interfaces (keeps the signature self-contained, avoids interface-file sprawl).
- Public methods of an exported class declare return types;
privatemethods infer (see return-types.md). Interface-pinned methods need not restate the type. - Export the class as a named export on the line it is defined.
interface ConstructorParams {
name: string;
isActive?: boolean;
}
export class Person {
private readonly name: string;
private isActive: boolean;
constructor({ name, isActive = true }: ConstructorParams) {
this.name = name;
this.isActive = isActive;
}
greet(): string {
return `Hello, my name is ${this.name}.`;
}
setActiveStatus({ status }: { status: boolean }): void {
this.isActive = status;
}
}
The proof
failsrc/people/Person.ts
interface GreetParams {
greeting: string;
}
// Positional constructor arguments, and a separate interface for a method that
// takes one property — both of the shapes the section rules out.
export class Person {
private readonly name: string;
constructor(name: string, isActive = true) {
this.name = isActive ? name : `${name} (inactive)`;
}
greet(params: GreetParams) {
return `${params.greeting}, my name is ${this.name}.`;
}
}
passsrc/people/Person.ts
interface ConstructorParams {
name: string;
isActive?: boolean;
}
export class Person {
private readonly name: string;
private isActive: boolean;
constructor({ name, isActive = true }: ConstructorParams) {
this.name = name;
this.isActive = isActive;
}
greet({ greeting }: { greeting: string }): string {
return `${greeting}, my name is ${this.name}.`;
}
setActiveStatus({ status }: { status: boolean }): void {
this.isActive = status;
}
isCurrentlyActive(): boolean {
return this.isActive;
}
}
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "class-syntax": "advisory" }"standards-checks": { "class-syntax": "off" }