简化 TypeScript 中的联合类型和数组
原文英文,约500词,阅读约需2分钟。发表于: 。When working with TypeScript, you might find yourself needing to define a union type and an array containing all of the possible values of that type. A common approach is to write something like...
在使用TypeScript时,通过`as const`和`typeof`可以将联合类型和数组合并定义,避免重复更新,提升类型安全和代码维护性。