Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

Not possible to narrow records down when wanting to listen to everything #7

Description

@Jiralite

Description

It does not seem possible to narrow down the union of records when wanting to listen to everything:

import { CommitType, EventType, Jetstream } from "@skyware/jetstream";

const jetstream = new Jetstream();

jetstream.on(EventType.Commit, (event) => {
	const commit = event.commit;

	if (commit.operation === CommitType.Create) {
		const record = commit.record;

		if (record.$type === "app.bsky.feed.post") {
			record.text; // Property 'text' does not exist...
		}
	}
});

jetstream.start();

I would have expected record to be of type AppBskyFeedPost.Record, but it was still AppBskyActorProfile.Record | AppBskyFeedGenerator.Record | AppBskyFeedLike.Record | AppBskyFeedPost.Record | AppBskyFeedPostgate.Record | AppBskyFeedRepost.Record | AppBskyFeedThreadgate.Record | AppBskyGraphBlock.Record | AppBskyGraphFollow.Record | AppBskyGraphList.Record | AppBskyGraphListblock.Record | AppBskyGraphListitem.Record | AppBskyGraphStarterpack.Record | AppBskyLabelerService.Record | ChatBskyActorDeclaration.Record.

tsconfig.json:

{
	"compilerOptions": {
		"strict": true,
		"module": "NodeNext",
		"moduleResolution": "NodeNext",
		"lib": ["ESNext"],
		"target": "ESNext",
	}
}

For now, just doing "text" in record suffices, I guess... unless I am being oblivious to something? If so, please let me know!

As a side note, I must skip the library check when type checking because it gives compile errors from partysocket. It's not strictly relevant to this package I guess.
index.ts:12:11 - error TS2339: Property 'text' does not exist on type 'AppBskyActorProfile.Record | AppBskyFeedGenerator.Record | AppBskyFeedLike.Record | AppBskyFeedPost.Record | AppBskyFeedPostgate.Record | AppBskyFeedRepost.Record | AppBskyFeedThreadgate.Record | AppBskyGraphBlock.Record | AppBskyGraphFollow.Record | AppBskyGraphList.Record | AppBskyGraphListblock.Record | ... 4 mor...'.
  Property 'text' does not exist on type 'Record'.

12    record.text;
             ~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:5:189 - error TS2304: Cannot find name 'AddEventListenerOptions'.

5     addEventListener<K extends keyof EventMap>(type: K, callback: (event: EventMap[K] extends Event ? EventMap[K] : never) => EventMap[K] extends Event ? void : never, options?: boolean | AddEventListenerOptions): void;
                                                                                                                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:6:46 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

6     addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:6:99 - error TS2304: Cannot find name 'EventListenerOptions'.

6     addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
                                                                                                    ~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:7:192 - error TS2304: Cannot find name 'AddEventListenerOptions'.

7     removeEventListener<K extends keyof EventMap>(type: K, callback: (event: EventMap[K] extends Event ? EventMap[K] : never) => EventMap[K] extends Event ? void : never, options?: boolean | AddEventListenerOptions): void;
                                                                                                                                                                                                 ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:8:49 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

8     removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:8:102 - error TS2304: Cannot find name 'EventListenerOptions'.

8     removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
                                                                                                       ~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:75:23 - error TS2304: Cannot find name 'BinaryType'.

75     get binaryType(): BinaryType;
                         ~~~~~~~~~~

node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:76:27 - error TS2304: Cannot find name 'BinaryType'.

76     set binaryType(value: BinaryType);
                             ~~~~~~~~~~


Found 9 errors in 2 files.

Errors  Files
     1  index.ts:12
     8  node_modules/.pnpm/partysocket@1.0.3/node_modules/partysocket/ws.d.ts:5

Versions

  • Node.js 22.12.0
  • @skyware/jetstream 0.2.2
  • @types/node 22.10.5
  • typescript 5.7.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions