在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
In this lesson, we're going to explore template literal types, another powerful feature of TypeScript's type system. Template literal types have the same syntax as template literals in JavaScript, but they're used in type positions. Using template literal types, we can produce a union of string literal types and perform string concatenation in the type space:
type MarginProperty = | "margin-block-start" | "margin-block-end" | "margin-inline-start" | "margin-inline-end"; type MarginUnit = "px" | "vh" | "vw"; type MarginValue = `${number}${MarginUnit}`; type MarginDeclaration = [MarginProperty, MarginValue]; const margin: MarginDeclaration = ["margin-block-start", "20vh"];
|
请发表评论