Last updated 5 years ago
Was this helpful?
型別別名用來給一個型別起個新名字。
type Name = string; type NameResolver = () => string; type NameOrResolver = Name | NameResolver; function getName(n: NameOrResolver): Name { if (typeof n === 'string') { return n; } else { return n(); } }
上例中,我們使用 type 建立型別別名。
type
型別別名常用於聯合型別。
()