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
26 changes: 26 additions & 0 deletions __tests__/typescript-stress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,32 @@ describe('Procedure error schema', () => {
),
);
});

test('spreading a flattened union into another union', () => {
const BaseErrorSchema = flattenErrorType(
Type.Union([
Type.Object({
code: Type.Literal('NOT_FOUND'),
message: Type.String(),
}),
Type.Object({
code: Type.Literal('PARSE_ERROR'),
message: Type.String(),
}),
]),
);

// Then we want to combine it with another error in a new union
const ExtendedErrorSchema = Type.Union([
Type.Object({
code: Type.Literal('NEW_ERROR'),
message: Type.String(),
}),
BaseErrorSchema,
]);

acceptErrorSchema(ExtendedErrorSchema);
});
});

describe('fails', () => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@replit/river",
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
"version": "0.210.0",
"version": "0.210.1",
"type": "module",
"exports": {
".": {
Expand Down
6 changes: 2 additions & 4 deletions router/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ function isUnion(schema: TSchema): schema is TUnion {
return schema[Kind] === 'Union';
}

type Flatten<T> = T extends BaseErrorSchemaType
export type Flatten<T> = T extends BaseErrorSchemaType
? T
: T extends TUnion<Array<infer U extends TSchema>>
? U extends BaseErrorSchemaType
? TUnion<Array<U>>
: Flatten<U>
? Flatten<U>
: unknown;

/**
Expand Down
Loading