Skip to content

Commit

Permalink
fix(schedule): expose other fields when id optional (#451)
Browse files Browse the repository at this point in the history
This PR appears to follow-up on
#276 which made it so `id`
was optional ✅ but did so in a way that removed the remainder of the
required fields from the type definition ❌, e.g. `actorTaskId` was no
longer recognized as a valid property as of v2.8.2

Because `ScheduleAction` is defined as a union of different types, we
must use [distributive conditional
types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types)
to capture the specific properties of the individual subtypes correctly.
  • Loading branch information
omikader committed Nov 10, 2023
1 parent 491e76b commit abe9d51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/resource_clients/schedule.ts
Expand Up @@ -9,7 +9,7 @@ import {
parseDateFields,
catchNotFoundOrThrow,
cast,
MakeOptional,
DistributiveOptional,
} from '../utils';

export class ScheduleClient extends ResourceClient {
Expand Down Expand Up @@ -93,7 +93,7 @@ export type ScheduleCreateOrUpdateData = Partial<
| 'isExclusive'
| 'description'
> & {
actions: MakeOptional<ScheduleAction, 'id'>[]
actions: DistributiveOptional<ScheduleAction, 'id'>[]
}
>;

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -201,4 +201,4 @@ export function cast<T>(input: unknown): T {

export type Dictionary<T = unknown> = Record<PropertyKey, T>;

export type MakeOptional<T, U extends keyof T> = Pick<T, Exclude<keyof T, U>> & Partial<Pick<T, U>>;
export type DistributiveOptional<T, K extends keyof T> = T extends any ? Omit<T, K> & Partial<Pick<T, K>> : never;

0 comments on commit abe9d51

Please sign in to comment.