Skip to content

fix(types): type the long-poll timer without the NodeJS namespace - #59

Open
mark1russell7 wants to merge 1 commit into
supabase:mainfrom
mark1russell7:fix-longpoll-timer-type
Open

mark1russell7 wants to merge 1 commit into
supabase:mainfrom
mark1russell7:fix-longpoll-timer-type

Conversation

@mark1russell7

Copy link
Copy Markdown

Issues are turned off in this repository, so this PR also carries the report.

Problem

priv/static/types/longpoll.d.ts declares currentBatchTimer: NodeJS.Timeout | null. Only @types/node declares the NodeJS namespace. A project without @types/node and with skipLibCheck: false (a browser app, for example) fails to compile when it imports @supabase/realtime-js, because those types import the types of this package.

The build gets the type from setTimeout. tsconfig.json names no types, and @types/node is in node_modules as a transitive dev dependency.

Repro

TypeScript 5.9.3, with longpoll.d.ts copied from priv/static/types at main (c605b95):

{ "compilerOptions": { "strict": true, "noEmit": true, "skipLibCheck": false, "lib": ["es2023", "dom"], "types": [] }, "files": ["longpoll.d.ts"] }
longpoll.d.ts(10,24): error TS2503: Cannot find namespace 'NodeJS'.

Fix

A JSDoc type on the field in assets/js/phoenix/longpoll.js: ReturnType<typeof setTimeout> | null. That is a number in browsers and a Timeout in Node.js. With the fix, the repro compiles.

I made longpoll.d.ts and its map again with TypeScript 5.9.3 (the version in package-lock.json) and the tsconfig.json of the repository. No other declaration file changed.


An AI coding assistant (Claude Code) wrote the fix, the repro and this text.

The declaration of LongPoll.currentBatchTimer was NodeJS.Timeout. Only
@types/node declares the NodeJS namespace, so a project with no
@types/node and skipLibCheck off fails with TS2503 when it imports
these types. A JSDoc type on the field gives ReturnType<typeof
setTimeout> | null, which fits browsers and Node.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant