Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/durably-react/src/client/use-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ export interface UseRunsClientOptions {

export interface UseRunsClientResult<
TInput extends Record<string, unknown> = Record<string, unknown>,
TOutput extends Record<string, unknown> | undefined =
| Record<string, unknown>
| undefined,
TOutput extends Record<string, unknown> | undefined = Record<string, unknown>,
> {
/**
* List of runs for the current page
Expand Down
4 changes: 1 addition & 3 deletions packages/durably-react/src/hooks/use-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export interface UseRunsOptions {
// where network errors don't occur.
export interface UseRunsResult<
TInput extends Record<string, unknown> = Record<string, unknown>,
TOutput extends Record<string, unknown> | undefined =
| Record<string, unknown>
| undefined,
TOutput extends Record<string, unknown> | undefined = Record<string, unknown>,
> {
/**
* List of runs for the current page.
Expand Down
8 changes: 2 additions & 6 deletions packages/durably-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ export type DurablyEvent =
*/
export type TypedRun<
TInput extends Record<string, unknown> = Record<string, unknown>,
TOutput extends Record<string, unknown> | undefined =
| Record<string, unknown>
| undefined,
TOutput extends Record<string, unknown> | undefined = Record<string, unknown>,
> = Omit<Run, 'input' | 'output'> & {
input: TInput
output: TOutput | null
Expand All @@ -142,9 +140,7 @@ export type { ClientRun } from '@coji/durably'
*/
export type TypedClientRun<
TInput extends Record<string, unknown> = Record<string, unknown>,
TOutput extends Record<string, unknown> | undefined =
| Record<string, unknown>
| undefined,
TOutput extends Record<string, unknown> | undefined = Record<string, unknown>,
> = Omit<ClientRun, 'input' | 'output'> & {
input: TInput
output: TOutput | null
Expand Down
18 changes: 18 additions & 0 deletions packages/durably-react/tests/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ describe('Type inference', () => {
expectTypeOf<Result['refresh']>().toBeFunction()
})

it('default type parameters exclude undefined from output', () => {
type DefaultRun = TypedRun

expectTypeOf<DefaultRun['output']>().toEqualTypeOf<Record<
string,
unknown
> | null>()
})

it('union types work for multi-job dashboards', () => {
type ImportRun = TypedRun<{ file: string }, { count: number }>
type SyncRun = TypedRun<{ userId: string }, { synced: boolean }>
Expand Down Expand Up @@ -243,6 +252,15 @@ describe('Type inference', () => {
expectTypeOf<Result['refresh']>().toBeFunction()
})

it('default type parameters exclude undefined from output', () => {
type DefaultRun = TypedClientRun

expectTypeOf<DefaultRun['output']>().toEqualTypeOf<Record<
string,
unknown
> | null>()
})

it('union types work for multi-job dashboards', () => {
type ImportRun = TypedClientRun<{ file: string }, { count: number }>
type SyncRun = TypedClientRun<{ userId: string }, { synced: boolean }>
Expand Down