import { Equal, Expect } from "../helpers/type-utils";
interface Attributes {
id: string;
email: string;
username: string;
}
/**
* How do we create a type helper that represents a union
* of all possible combinations of Attributes?
*/
type ObjectToUnion<T> = {
[Key in keyof T]: Record<Key, T[Key]>;
}[keyof T];
type ExclusiveAttributes = ObjectToUnion<Attributes>;
type tests = [
Expect<
Equal<
ExclusiveAttributes,
| {
id: string;
}
| {
email: string;
}
| {
username: string;
}
>
>
];
标签:Typescript,string,Union,Object,keyof,136,type From: https://www.cnblogs.com/Answer1215/p/16982343.html