typescript/consistent-type-definitions 樣式
作用
強制型別定義一致地使用介面 (interface) 或型別 (type)。
為什麼這不好?
TypeScript 提供了兩種常見的方式來定義物件型別:介面 (interface) 和型別 (type)。兩者通常非常相似,並且可以經常互換使用。一致地使用相同的型別宣告風格有助於程式碼的可讀性。
範例
ts
// incorrect, when set to "interface"
type T = { x: number };
// incorrect when set to "type"
interface T {
x: number;
}