Skip to content

Commit

Permalink
fix(Simulations): Update types for list and update for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
danbillson committed Oct 8, 2024
1 parent be3ae08 commit ec0ef62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/resources/simulations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const SimulationPaths = {
} as const;

export class SimulationsResource extends BaseResource {
public list<T extends IEventName | SimulationScenarioType>(
queryParams?: ListSimulationQueryParameters,
): SimulationCollection<T> {
public list(queryParams?: ListSimulationQueryParameters): SimulationCollection<IEventName | SimulationScenarioType> {
const queryParameters = new QueryParameters(queryParams);
return new SimulationCollection(this.client, SimulationPaths.list + queryParameters.toQueryString());
}
Expand Down Expand Up @@ -62,14 +60,14 @@ export class SimulationsResource extends BaseResource {

public async update<T extends IEventName | SimulationScenarioType>(
simulationId: string,
updateSimulation: UpdateSimulationRequestBody,
updateSimulation: UpdateSimulationRequestBody<T>,
): Promise<Simulation<T>> {
const urlWithPathParams = new PathParameters(SimulationPaths.update, {
simulation_id: simulationId,
}).deriveUrl();

const response = await this.client.patch<
UpdateSimulationRequestBody,
UpdateSimulationRequestBody<T>,
Response<ISimulationResponse<T>> | ErrorResponse
>(urlWithPathParams, updateSimulation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import type { SimulationScenarioType, Status } from '../../../enums';
import type { IEventName } from '../../../notifications';
import type { EventMap, IEventName } from '../../../notifications';

export interface UpdateSimulationRequestBody {
export interface UpdateSimulationRequestBody<T extends IEventName | SimulationScenarioType> {
notificationSettingId?: string;
name?: string;
status?: Status;
type?: IEventName | SimulationScenarioType;
payload?: any;
type?: T;
payload?: (T extends IEventName ? EventMap[T] : null) | null;
}

0 comments on commit ec0ef62

Please sign in to comment.