Skip to content

chore: add a typecheck gate and align TypeScript versions - #211

Open
childrentime wants to merge 3 commits into
mainfrom
chore/add-typecheck
Open

chore: add a typecheck gate and align TypeScript versions#211
childrentime wants to merge 3 commits into
mainfrom
chore/add-typecheck

Conversation

@childrentime

Copy link
Copy Markdown
Owner

Problem

The repo had no working tsc invocation, and no typecheck script. Neither config was clean on main:

  • packages/core/tsconfig.json7 errors
  • root tsconfig.json258 errors, all from zod@4.4.3's .d.cts, which the pinned TypeScript 4.9.5 cannot parse

Underneath that sat a version split: root TypeScript was 4.9.5, packages/core's was 5.8.3. The two disagree about lib.domGeolocationCoordinates.toJSON exists in 5.8 but not in 4.9 — so an editor picking up the root TypeScript flags code that CI requires, and vice versa.

Changes

The gate

  • typecheck (tsc --noEmit) on @reactuses/core, plus a root passthrough, wired into CI after lint.

The version split

  • Root TypeScript ^4.9.5^5.8.3, matching packages/core.
  • typescript.tsdk → the workspace TypeScript, so editors and CI resolve the same lib.dom.

The 7 pre-existing errors

  • useGeolocation: initCoord gains the toJSON that lib.dom now requires. It returns its own fields, so JSON.stringify output is unchanged; the constant is internal (not exported from src/index.ts).
  • useOrientation: ScreenOrientation.lock() ships in browsers but is absent from lib.dom, which declares only unlock() — narrowed via a local interface rather than an any cast.
  • Specs: two genuinely unused params prefixed with _; useMap's reset case widened past its as const literals, since that test adds a third key.

No runtime behavior changes.

Verification

pnpm typecheck, pnpm lint, pnpm build, and the full 307-test suite all pass. Full suite run 3× on this branch and 3× on main — see the note below.

Notes for review

1. An unrelated bug I did not touch. useOrientation's lock guards look inverted:

const lockOrientation = (type: UseOrientationLockType) => {
  if (isBrowser) {
    return          // isBrowser === true means we ARE in a browser
  }
  ...
  return window.screen.orientation.lock(type)
}

With isBrowser = typeof window !== 'undefined', this returns early in every browser — so lockOrientation / unlockOrientation are no-ops where they should work, and fall through to touch window during SSR. Neither is covered by index.spec.ts. Left alone deliberately: it's a behavior fix, not a type fix, and belongs in its own PR.

2. A flaky test, pre-existing. useDebounce/index.spec.ts failed twice under full-suite parallel load, both times immediately after a heavy install + build. It passes 5/5 in isolation and 3/3 on the full suite once the machine is quiet — and main shows 3/3 as well, so it is timing sensitivity rather than anything in this change. Worth watching once CI runs it on shared runners.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

childrentime and others added 3 commits July 30, 2026 00:15
The repo had no working `tsc` invocation. Neither config was clean on main:
`packages/core/tsconfig.json` reported 7 errors, and the root config — pinned to
TypeScript 4.9.5 — produced 258 just parsing zod's .d.cts.

- Add `typecheck` (`tsc --noEmit`) to @reactuses/core and a root passthrough,
  wired into CI after lint.
- Align root TypeScript 4.9.5 -> ^5.8.3 to match packages/core. The two versions
  disagreed about lib.dom, so an editor using the root TS flagged code that CI
  required (GeolocationCoordinates.toJSON exists in 5.8, not in 4.9).
- Point `typescript.tsdk` at the workspace TypeScript so editors and CI agree.

Fixes the 7 pre-existing errors:
- useGeolocation: give `initCoord` the `toJSON` that lib.dom now requires; it
  returns its own fields, so JSON output is unchanged.
- useOrientation: `ScreenOrientation.lock()` ships in browsers but is absent
  from lib.dom, which declares only `unlock()` — narrow via a local interface.
- Specs: prefix two genuinely unused params with `_`, and widen the `as const`
  entries in useMap's reset case, which adds a third key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CI caught what a local run could not: scripts/tsdoc.ts imports
@reactuses/ts-document, whose `lib/` output is gitignored. It resolves on a
machine where that package has been built and never on a fresh checkout.

Point the gate at a dedicated tsconfig covering src, global.d.ts and
jest-setup.ts. Specs stay in — 4 of the 7 errors this PR fixes were in specs,
and reverting either a source or a spec fix still fails the gate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lost to a stray `git checkout main -- <path>` while verifying the gate; that
form stages the file, so it rode along in the previous commit unnoticed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
return Promise.reject(new Error('Not supported'))
}
return window.screen.orientation.lock(type)
return (window.screen.orientation as LockableScreenOrientation).lock(type)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the inverted guard you mention in the description — isBrowser is
typeof window !== 'undefined', so lockOrientation / unlockOrientation
return early exactly when we are in a browser, and only ever reach
window.screen during SSR. Happy to pick this up as a follow-up PR with
tests, if nobody else is on it.

@ostapondo ostapondo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — went through the whole diff, turned up nothing. The typecheck scope
(src + global.d.ts + jest-setup, scripts excluded) makes sense.

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.

2 participants