|
|
@ -59,3 +59,28 @@ export class Model<U extends {types?: {[key: string]: unknown} | {}, context?: R |
|
|
|
|
|
|
|
|
|
|
|
computed: {[key: string]: () => unknown} | {}; |
|
|
|
computed: {[key: string]: () => unknown} | {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 分享一段很好看的代码 |
|
|
|
|
|
|
|
// union to intersection of functions
|
|
|
|
|
|
|
|
type UnionToIoF<U> = |
|
|
|
|
|
|
|
(U extends any ? (k: (x: U) => void) => void : never) extends |
|
|
|
|
|
|
|
((k: infer I) => void) ? I : never |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return last element from Union
|
|
|
|
|
|
|
|
type UnionPop<U> = UnionToIoF<U> extends { (a: infer A): void; } ? A : never; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// prepend an element to a tuple.
|
|
|
|
|
|
|
|
type Prepend<U, T extends ReadonlyArray<any>> = |
|
|
|
|
|
|
|
((a: U, ...r: T) => void) extends (...r: infer R) => void ? R : never; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type UnionToTupleRecursively<Union, Result extends ReadonlyArray<any>> = { |
|
|
|
|
|
|
|
1: Result; |
|
|
|
|
|
|
|
0: UnionToTupleRecursively_<Union, UnionPop<Union>, Result>; |
|
|
|
|
|
|
|
// 0: UnionToTupleRecursively<Exclude<Union, UnionPop<Union>>, Prepend<UnionPop<Union>, Result>>
|
|
|
|
|
|
|
|
}[[Union] extends [never] ? 1 : 0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type UnionToTupleRecursively_<Union, Element, Result extends ReadonlyArray<any>> = |
|
|
|
|
|
|
|
UnionToTupleRecursively<Exclude<Union, Element>, Prepend<Element, Result>>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type UnionToTuple<U> = UnionToTupleRecursively<U, []>; |
|
|
|
|
|
|
|
*/ |