fix(types): move timer declarations into declare-global so bare calls resolve them - #8828
Open
axuj wants to merge 1 commit into
Open
fix(types): move timer declarations into declare-global so bare calls resolve them#8828axuj wants to merge 1 commit into
axuj wants to merge 1 commit into
Conversation
… resolve them common/global.d.ts is a module (it imports SystemInfo et al.), and the four bare 'declare function' timer declarations sat OUTSIDE its declare-global block. Module-scoped declarations are private: bare-global call sites in application code never resolved to them — every ReactLynx/Rspeedy project silently fell back to @types/node or DOM signatures instead, which accept forwarded extra args that Lynx host timers actually drop (js_app.cc / napi_lepus_lynx.cc fire the callback zero-arg), so forwarded calls pass typecheck yet break on device. Move the four declarations inside declare-global (signature unchanged, misleading parameter name 'number' renamed to 'delay') and document the two-arg contract.
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.
Problem
The four timer declarations in
js_libraries/types/types/common/global.d.tssit outside the file'sdeclare global {}block. That file is a module (top-level imports), so these module-scopeddeclare functions are private — bare-global call sites in application code never resolve to them. Every ReactLynx/Rspeedy project instead falls back to injected@types/nodeor DOM signatures, which accept forwarded extra args.Lynx host timers actually drop forwarded args and fire the callback zero-arg (
core/runtime/js/bindings/js_app.cc,core/runtime/lepusng/napi/worklet/napi_lepus_lynx.cc— both consume only callback+delay and invoke with an empty arg list), so code likesetTimeout(fn, ms, arg)passes typecheck yet silently breaks on device.Our project hit this exact bug: a bottom-sheet close callback scheduled via
setTimeout(fn, duration, target, dismiss, generation)worked on web and never fired on device, leaving UI state stuck (icon never reset).Evidence in this repo
examples/vanilla/src/rspeedy-env.d.tsalready works around it by hand:Fix
Move the four declarations inside the existing
declare global {}block so they reach global scope. Signatures unchanged; misleading parameter namenumberrenamed todelay.Validation
Package
tsc --noEmit✅Package
vitest --typecheck --run: 24 files / 85 tests ✅Minimal consumer repro: axuj/lynx-types-timer-repro — open it directly in StackBlitz (WebContainers, zero setup):
https://stackblitz.com/github/axuj/lynx-types-timer-repro?file=README.md
In the StackBlitz terminal:
npm run afterproves both halves of the fix: bare two-arg calls resolve against the mounted declarations, and forwarded-extra-arg calls fail typecheck withTS2554, matching real device behavior.