TypeScript 小技巧

Coco

1分鐘閱讀

2024-09-03

satisfies 保留字面量寬度,又能校驗類型。

  • as const 固化元組
  • satisfies 用於配置物件
const routes = { home: "/", post: "/posts/:slug", } satisfies Record<string, string>;

小工具satisfies + const 組合最常用。