src/content/docs/assist/actions/use-sorted-interface-members.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components'; import EditorAction from "@/components/EditorAction.astro";
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v2.4.0` - Diagnostic Category: [`assist/source/useSortedInterfaceMembers`](/reference/diagnostics#diagnostic-category) - Sources: - Inspired from [`perfectionist/sort-interfaces`](https://perfectionist.dev/rules/sort-interfaces)## Description
Sort interface members by key.
Interface members are sorted according to their names. The rule distinguishes between
two types of members:
**Sortable members** - Members with explicit, fixed names that can be alphabetically sorted:
- Property signatures: `property: type`
- Method signatures: `method(): type`
- Getter signatures: `get property(): type`
- Setter signatures: `set property(value: type): void`
**Non-sortable members** - Members without fixed names or with dynamic/computed names:
- Call signatures: `(): type` (represents the interface as a callable function)
- Construct signatures: `new (): type` (represents the interface as a constructor)
- Index signatures: `[key: string]: type` (represents dynamic property access)
The rule sorts all sortable members alphabetically and places them first,
followed by non-sortable members in their original order. Non-sortable members
cannot be meaningfully sorted by name since they represent different interface
contracts rather than named properties or methods.
# Examples
## Invalid
```ts
interface MixedMembers {
z: string;
a: number;
(): void; // Call signature
y: boolean;
new (): MixedMembers; // Construct signature
b: string;
[key: string]: any; // Index signature
}
interface MixedMembers {
a: number;
b: string;
y: boolean;
z: string;
(): void; // Non-sortable members remain in original order
new (): MixedMembers;
[key: string]: any;
}