Skip to content

useSortedInterfaceMembers (JavaScript)

Language JavaScript (and super languages)
.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useSortedInterfaceMembers.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"useSortedInterfaceMembers": "on"
}
}
}
}

Sort named members of a TypeScript interface.

The action uses natural order, which compares numbers by value so that item9 comes before item10. It can sort members with fixed names:

  • properties: property: type;
  • methods: method(): type;
  • getters: get property(): type;
  • setters: set property(value: type): void.

Members without a fixed name cannot be sorted by name:

  • call signatures such as (): type make the interface callable;
  • construct signatures such as new (): type make it constructible;
  • index signatures such as [key: string]: type describe dynamically named properties;
  • computed names such as [Symbol.iterator]() are calculated from an expression.

The action places sorted, named members first. It keeps members without fixed names in their original relative order after them.

interface MixedMembers {
z: string;
a: number;
(): void; // Call signature
y: boolean;
new (): MixedMembers; // Construct signature
b: string;
[key: string]: any; // Index signature
}
code-block.ts:1:1 assist/source/useSortedInterfaceMembers  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The interface members are not sorted by key.

> 1 │ interface MixedMembers {
│ ^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ z: string;
> 3 │ a: number;
> 4 │ (): void; // Call signature
> 5 │ y: boolean;
> 6 │ new (): MixedMembers; // Construct signature
> 7 │ b: string;
> 8 │ [key: string]: any; // Index signature
> 9 │ }
│ ^
10 │

ℹ Safe fix: Sort the interface members by key.

1 1 │ interface MixedMembers {
2 │ - ··z:·string;
3 │ - ··a:·number;
4 │ - ··():·void;··//·Call·signature
5 │ - ··y:·boolean;
6 │ - ··new·():·MixedMembers;··//·Construct·signature
7 │ - ··b:·string;
2 │ + ··a:·number;
3 │ + ··b:·string;
4 │ + ··y:·boolean;
5 │ + ··z:·string;
6 │ + ··():·void;··//·Call·signature
7 │ + ··new·():·MixedMembers;··//·Construct·signature
8 8 │ [key: string]: any; // Index signature
9 9 │ }

interface MixedMembers {
a: number;
b: string;
y: boolean;
z: string;
(): void; // Non-sortable members remain in original order
new (): MixedMembers;
[key: string]: any;
}

When enabled, members separated by a blank line are kept in their own section and sorted only within that section. This preserves logical groupings that the author intentionally introduced with empty lines.

Default: false

biome.json
{
"assist": {
"actions": {
"source": {
"useSortedInterfaceMembers": {
"level": "on",
"options": {
"partitionByNewLine": true
}
}
}
}
}
}

With the option enabled, the following interface is considered sorted because each section is sorted on its own:

interface User {
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
name: string;
passwordHash: string;
}