lundi 19 octobre 2020

Applying Strategy Pattern in Typescript

I have the following method in a class that implements an interface:

async getStatuses(
        Id: string,
        context: Context,
        forDeletion?: boolean
    ): Promise<Partial<DataObject> | DeleteStatus> {
....
    .....
         ......
}

I need to replace the last optional parameter forDeletion? with a mapping function, applying the Strategy Design Pattern, to something similar to this 👇 , which I'm not sure how to do it neither if this is correct or not:

async <T> getStatuses(Id: string,
                      context: Context,
                      fn: Partial<DataObject> => T = (d: Partial<DataObject>) => d)
          ): Promise<Partial<DataObject> | T>

My goal is to replace the boolean flag forDeletion and apply strategy pattern, this way I will have the flexibility to map the status to anything I might need in the future.

Aucun commentaire:

Enregistrer un commentaire