我想知道是否有一種方法可以連接兩種打字稿型別作為一個例子:
type Size = 'xl' | 'xxl' ...;
let textSize: 'text-' & Size;
// So my type is something like : 'text-xl' | 'text-xxl'
uj5u.com熱心網友回復:
通過使用模板文字型別。
type Size = 'xl' | 'xxl';
type TextSizeType = `text-${Size}`;
TS 決議TextSizeType為
type TextSizeType = "text-xl" | "text-xxl"
這聽起來像你想要的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/406982.html
標籤:
上一篇:JavaScript:按物件中的屬性對物件陣列進行分組
下一篇:忽略非必填欄位
