Repository navigation
fix(types): type the long-poll timer without the NodeJS namespace - #59
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues are turned off in this repository, so this PR also carries the report.
Problem
priv/static/types/longpoll.d.tsdeclarescurrentBatchTimer: NodeJS.Timeout | null. Only@types/nodedeclares theNodeJSnamespace. A project without@types/nodeand withskipLibCheck: 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.jsonnames notypes, and@types/nodeis innode_modulesas a transitive dev dependency.Repro
TypeScript 5.9.3, with
longpoll.d.tscopied frompriv/static/typesatmain(c605b95):{ "compilerOptions": { "strict": true, "noEmit": true, "skipLibCheck": false, "lib": ["es2023", "dom"], "types": [] }, "files": ["longpoll.d.ts"] }Fix
A JSDoc type on the field in
assets/js/phoenix/longpoll.js:ReturnType<typeof setTimeout> | null. That is a number in browsers and aTimeoutin Node.js. With the fix, the repro compiles.I made
longpoll.d.tsand its map again with TypeScript 5.9.3 (the version inpackage-lock.json) and thetsconfig.jsonof the repository. No other declaration file changed.An AI coding assistant (Claude Code) wrote the fix, the repro and this text.