export type Constructor = new(...args: any[]) => T; /** * 注册widget */ export function shortcut() { return function decorator(Target: Constructor & {xtype: string}): void { BI.shortcut(Target.xtype, Target); }; } /** * 注册model */ export function model() { return function decorator}>(Target: U): void { BI.model(Target.xtype, Target); }; } /** * 类注册_store属性 * @param Model model类 * @param opts 额外条件 */ export function store(Model: Constructor & {xtype: string}, opts: { props?(this: unknown): { [key: string]: unknown } } = {}) { return function classDecorator(constructor:U) { return class extends constructor { _store() { const props = opts.props ? opts.props.apply(this) : undefined; return BI.Models.getModel(Model.xtype, props); } }; }; } /** * Model基类 */ export class Model} = {}> extends Fix.Model { // @ts-ignore this["computed"][key]为空 model: Pick<{[key in keyof U["types"]]: U["types"][key]}, U["context"][number]> & {[key in keyof ReturnType]: ReturnType[key]} & {[key in keyof this["computed"]]: ReturnType}; store: this["actions"]; state(): {[key: string]: unknown} | {} { return {}; } context: U["context"]; actions:{[key: string]: (...args: any[]) => any}; childContext: ReadonlyArray)>; // @ts-ignore this["computed"][key]为空 TYPE: Pick<{[key in keyof this["computed"]]: ReturnType} & {[key in keyof ReturnType]: ReturnType[key]}, this["childContext"][number]>; computed: {[key: string]: () => unknown} | {}; } /* 分享一段很好看的代码 // union to intersection of functions type UnionToIoF = (U extends any ? (k: (x: U) => void) => void : never) extends ((k: infer I) => void) ? I : never // return last element from Union type UnionPop = UnionToIoF extends { (a: infer A): void; } ? A : never; // prepend an element to a tuple. type Prepend> = ((a: U, ...r: T) => void) extends (...r: infer R) => void ? R : never; type UnionToTupleRecursively> = { 1: Result; 0: UnionToTupleRecursively_, Result>; // 0: UnionToTupleRecursively>, Prepend, Result>> }[[Union] extends [never] ? 1 : 0]; type UnionToTupleRecursively_> = UnionToTupleRecursively, Prepend>; type UnionToTuple = UnionToTupleRecursively; */