Skip to content

Commit b50354c

Browse files
committed
use .brand instead
1 parent 385b58a commit b50354c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/room/src/types/_common.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import z from 'zod';
12
import type { Pdu, PduType } from './v3-11';
23

34
export declare const __brand: unique symbol;
45

56
export type Brand<B> = { [__brand]: B };
67
export type Branded<T, B> = T & Brand<B>;
78

8-
export type EventID = Branded<string, 'EventID'>;
9-
109
export type StateKey = string;
1110

11+
export const eventIdSchema = z.string().brand('EventID');
12+
13+
export type EventID = z.infer<typeof eventIdSchema>;
14+
1215
export type StateMapKey = `${PduType}:${StateKey}`;
1316

1417
export type State = Map<StateMapKey, EventID>;

packages/room/src/types/v3-11.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { z } from 'zod';
2-
import { EventID, PduForType } from './_common';
3-
4-
export const eventIdSchema = z.string().transform((val) => val as EventID);
2+
import { PduForType, eventIdSchema } from './_common';
53

64
// Copied from: https://github.com/element-hq/synapse/blob/2277df2a1eb685f85040ef98fa21d41aa4cdd389/synapse/api/constants.py#L103-L141
75

@@ -536,8 +534,7 @@ export const PduNoContentTimelineEventSchema = {
536534
.array(eventIdSchema)
537535
.describe(
538536
'A list of event IDs that are required in the room state before this event can be applied. The server will not send this event if it is not satisfied.',
539-
)
540-
.transform((val) => val as EventID[]),
537+
),
541538
depth: z
542539
.number()
543540
.describe(

0 commit comments

Comments
 (0)