Hi, does someone know why .maxSlippage is still possibly undefined on the last lines?
type ConversationStep<T> = (
conversation: Conversation<SessionCtx>,
ctx: SessionCtx
) => Promise<any>;
/**
* Class that represents a conversation
*/
export abstract class PerpieConversation<T extends {}> {
/**
* The arguments storage of this conversation.
* It needs to be fully completed at the end of the conversation.
*/
protected abstract arguments: Partial<T>;
/**
* The steps of this conversation.
* A conversation is just a set of steps, each step may do some stuff
* and set some #arguments values, that the next steps can use, until conversation is complete.
*
* Each step can accept keys of T, which asserts these fields are done before moving onto it
* (compile time).
*/
protected abstract steps: ConversationStep<T>[];
// ======= Internal ======== //
protected assertValues<K extends keyof T>(
keys: K[]
): this is PerpieConversation<T> & {
arguments: RequireFields<Partial<T>, K>;
} {
for (const key of keys) {
if (!this.arguments[key]) {
throw `Failure In ${
this.#id
} Conversation - Requested ${keys} to be defined, but ${String(
key
)} was not defined. Arguments state: ${this.arguments}`;
}
}
return true;
}
}
class OpenPosition extends PerpieConversation<IncreasePositionParams> {
constructor(
id: ACTION_NAMES,
preparedArguments: Partial<IncreasePositionParams> = {}
) {
super(id, preparedArguments);
}
protected arguments: Partial<IncreasePositionParams> = {};
steps: ConversationStep<IncreasePositionParams>[] = [
async () => {
this.assertValues(["maxSlippage"]);
this.arguments.maxSlippage + 5;
},
];
}