TypeScript Intersection Types All In One
TypeScript Intersection Types All In One
交叉类型(类型合并)
interface A { a: number }
interface B { b: number }
var ab: A & B = { a: 1, b: 1 };
var a: A = ab;
// A & B assignable to A
var b: B = ab;
// A & B assignable to B
interface X { p: A }
interface Y { p: B }
var xy: X & Y = { p: ab };
// X & Y has property p of type A & B
type F1 = (a: string, b: string) => void;
type F2 = (a: number, b: number) => void;
var f: F1 & F2 = (a: string | number, b: string | number) => { };
f("hello", "world");
// Ok
f(1, 2);
// Ok
f(1, "test");
// Error
refs
https://github.com/microsoft/TypeScript/blob/main/doc/spec-ARCHIVED.md#35-intersection-types
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15868443.html
未经授权禁止转载,违者必究!

浙公网安备 33010602011771号