Typescript中是否有办法说“我希望此类型基于字符串(或任何其他原始类型),但是表现得好像它们不兼容”?基本上,我想表达一下:
type Name = string
type EmailAddress = string
function getPerson(name: Name, email: EmailAddress): Person { ... }
const name: Name = "Dummy"
const email: EmailAddress = "dummy@localhost"
const person = getPerson(email, name) // error: EmailAddress used as Name
但是没有定义类或将其放入接口的开销。