[Typescript] Intersections types
typescript types
2023-09-14 08:59:13 时间
interface Order { id: string; amount: number; currency: string; } interface Stripe { card: string; cvc: string; } interface PayPal { email: string; } type CheckoutCard = Order & Stripe; type CheckoutPayPal = Order & PayPal; const order: Order = { id: 'xj28s', amount: 100, currency: 'USD' }; const orderCard: CheckoutCard = { ...order, card: '1000 2000 3000 4000', cvc: '123' }; const orderPayPal: CheckoutPayPal = { ...order, email: 'abc@def.com' };
Object.assign: in typescript, it can understand the intersection:
const assigned = Object.assign({}, order, orderCard); // assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
相关文章
- typescript web_typescript在线运行
- typeScript 全局库 文件声明
- 记一次vscode踩坑记录:"TypeScript 语言服务在其启动后已中止 5 次。将不会重启该服务。"
- typeScript学习总结(二)
- TypeScript,我从不喜欢到沉迷
- 解释器模式举例-TypeScript 类型体操天花板,用类型运算写一个 Lisp 解释器
- typescript [接口]
- (一)为什么要使用 TypeScript(二)安装并配置 Ts
- 掌握 TypeScript:20 个提高代码质量的最佳实践
- TypeScript 5.0 现已发布:全新的装饰器,速度、内存和包大小优化
- TypeScript实例_手动编译与自动编译、类型注解、接口和类的详解