我刚问过can not find type the return value of a class factory function,提供的方法在我的抽象中起作用,但是当我在实际代码中实现该方法时,我仍然遇到类型错误,我想修复IParticipantCommands以输出正确的类型,但是我尝试的所有事情都会给我带来错误
interface IParticipantCommands {
AddParticipantCommand: new (s: INewParticipantDTO) => INexusCommand<INewParticipantDTO>;
}
export function participantCommandFactory(args: IParticipantCommandFactoryArgs): IParticipantCommands {
const ParticipantCommand = moduleCommandFactory(args);
class AddParticipantCommand extends ParticipantCommand<INewParticipantDTO> {
public getType(): CommandType<string, string> {
return {
subject: ParticipantCommandSubject.PARTICIPANT,
verb: ParticipantCommandVerb.ADD,
};
}
}
return {
AddParticipantCommand,
};
}
以上代码中使用的其他接口和功能
export interface INexusCommand<T> extends ICommand, Command<T, string, string> {
readonly type: CommandType<string, string>;
}
export function moduleCommandFactory({ domain, module }: CommandFactoryArgs) {
return class Command<T> implements INexusCommand<T> {
public readonly body: T;
public readonly type: CommandType<string, string>;
public readonly header: CommandHeader & { uuid: UUID }; // Don't type uuid as UUID | null
constructor(body: T, user: ModuleObject, organization: ModuleObject) {
this.type = this.getType();
this.body = body;
this.header = {
timestamp: Date.now(),
uuid: uuid.v4(),
saga: uuid.v4(),
domain,
module,
organization,
user,
};
}
getType(): CommandType<string, string> {
throw new Error('Command must specify getType() function');
}
};
}
export interface INewParticipantDTO extends Omit<IParticipant, 'id'> {}
export interface IParticipant extends IModuleLink {
id: UUID;
/**
* what is there "job" related to the module ( What they should do ) and can be defined on a per module basis
* Note: this does not have any relationship to what they are Allowed/Authorized to do, someone could be a "Manager" and not have any ability to edit or view anything
*/
roles: string[];
/**
* what are they authorized to do
*/
scopes: TParticipantScope[];
/**
* Last time this participant interacted with they module
*/
last_interaction: ISODATE | null;
}