Fix historyContext and RollbarContext typings, type-check index.d.ts in CI (#69) - #162
Conversation
AI Agent Review (openai, openai-astra)No findings: the new typings match what the code actually does, and the typecheck setup is correctly wired. Typings vs. runtime
Typecheck wiring
Non-blocking notes (not findings)
The diff doesn't show whether |
2af58f5 to
2e25b00
Compare
rollbar-circleci-machine
left a comment
There was a problem hiding this comment.
AI Agent Review (openai, openai-astra)
Review of #162: fix the historyContext / RollbarContext typings and type-check index.d.ts in CI
The typings now match the runtime.
historyContext:src/history-context.js:23-37passes a location object toformatter/filterand accepts both the history v4(location, action)and v5({ location, action })listener forms. The newHistoryLocation/HistoryContextOptions/HistoryContextListenertypes inindex.d.ts:89-112describe exactly that. Understrict, a v4listenmatches the first overload and a v5listenmatches the second.RollbarContext:contextis now required andonRenderis added, matching the propTypes insrc/rollbar-context.js:8-12.- Compatibility note: TypeScript users who left out
context, or typedformatter/filterwith a string argument, will get new compile errors. That is the intended fix, since both already failed at runtime, but it may be worth a changelog line.
The compile-time tests look sound.
src/tests/types.test-d.tsxdoesn't match Jest's default test pattern (roots atjest.config.js:5) or the testing-library ESLint override (.eslintrc.json:36-37), so onlynpm run typecheckruns it.- It imports the real
index.d.tsthroughsrc/tests/rollbar-react/package.json:3. - Each
@ts-expect-errorsits directly above the line where the error is reported, so the directive will be flagged as unused if the typings get looser. - The updated
history-context.test.tscalls type-check without the oldas nevercasts.
scripts/typecheck.ts works on Linux CI but not on Windows. The approach is reasonable: a full program check, then drop diagnostics from files under node_modules, instead of skipLibCheck, which would also skip index.d.ts. The API calls look right for the pinned typescript 5.3.3 (package-lock.json:13003-13004). The one problem: the filter splits file names on path.sep. TypeScript always stores file names with /, so on Windows nothing is filtered and the script fails on the third-party typing errors it is meant to ignore. CI runs on ubuntu-latest, so CI is not affected.
Outside the changed lines (not a finding): index.d.ts:44 still requires children: ReactNode on RollbarContext, while the propTypes at src/rollbar-context.js:11 treat it as optional. This was already the case before this PR.
I didn't run anything for this review, and the diff doesn't show whether npm run typecheck, lint or the tests pass.
AI Agent Review (openai, openai-astra)No confirmed defects. This looks good to merge. The new
This diff doesn't show CI results, so I can't confirm the new type check passes. Non-blocking notes (I couldn't read the TypeScript source here because
|
rollbar-circleci-machine
left a comment
There was a problem hiding this comment.
AI Agent Review (openai, openai-astra)
Review: typings fix for historyContext / RollbarContext, plus a CI type check
I read index.d.ts, the runtime code (src/history-context.js, src/rollbar-context.js), tsconfig.json, jest.config.js, the ESLint config, the CI workflow and the new/changed tests.
What checks out:
RollbarContextprops now match the runtime propTypes:contextis required,onRenderis an optional bool,childrenis optional (src/rollbar-context.js:8-12). Makingcontextrequired breaks TS consumers who left it out, but it matches the runtime contract. It may be worth a changelog note.- The two call forms on
HistoryContextListenermatch what the runtime does (src/history-context.js:23-28). Under TS's rules for assigning overloaded functions, the listener can be passed to the v4(location, action)shape and the v5({ location, action })shape used intypes.test-d.tsx. - Jest won't pick up
types.test-d.tsx: it doesn't match the defaulttestMatch, andjest.config.jsdoesn't override it. Each@ts-expect-errorsits on the line where TS reports the error: the JSX opening tag or attribute, or the single-line call. scripts/typecheck.tsreadstsconfig.json, which has noinclude, so rootindex.d.ts,scripts/andsrc/tests/are all checked, andexamplesandnode_modulesare excluded. The TS API calls look right for the pinned TypeScript 5.3.3 (package-lock.json:13004). The build outputs (dist,lib,bundles) are JS only, so they don't leak into the program.
Could not verify: node_modules is not installed in this checkout, so I couldn't run npm run typecheck, Jest or ESLint. The diff doesn't show any results either.
One low-severity finding: formatter and filter are declared as function-typed properties, so with strict on TS checks their parameters contravariantly. The README tells users that location/action are history.location/history.action. If they annotate their callbacks with the history package's Location/Action types, compilation fails. Declaring the two options with method syntax fixes it and keeps the new @ts-expect-error cases failing as intended.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests were plain JS only because index.d.ts on main had no `onRender`. Stacked on #162 they type-check as TSX, like the other component tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
[P3] Accept callbacks annotated with
|
|
Thanks, this is addressed:
|
AI Agent Review (openai, openai-astra)No defects found; findings are empty. I did not run tsc, Jest or ESLint, so this review is based only on reading the code. historyContext typings match the runtime. RollbarContext typings match its propTypes. The type tests and typecheck script do what they claim. Each Notes (not defects):
|
AI Agent Review (openai, openai-astra)No problems worth an inline comment.
Non-blocking notes
I didn't run anything, so I can't say whether CI passes. |
historyContext's typings described neither history v4 nor v5:
formatter/filter received `location: string` (it is a Location object)
and the returned listener's first argument was typed as
`{ action; filter }`. The listener is now an overloaded callable that
matches both `history.listen` signatures, and locations are a small
structural HistoryLocation so there is no dependency on `history`.
RollbarContext's typings had `context` optional (the component requires
it) and were missing the `onRender` prop.
A new `npm run typecheck` (scripts/typecheck.ts) type-checks the project,
index.d.ts included, and fails on any error outside node_modules. It runs
in CI. `--skipLibCheck` would have skipped index.d.ts too, while plain
`tsc` fails on errors inside rollbar 3's own typings.
src/tests/types.test-d.tsx pins the public typings with positive and
@ts-expect-error cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…text children - scripts/typecheck.ts: split SourceFile.fileName on '/' instead of path.sep. TypeScript stores file names with forward slashes on every platform, so on Windows the path.sep split found no node_modules segment and the dependency errors the script ignores were reported. - index.d.ts: RollbarContext `children` is optional, matching `children: PropTypes.node` in src/rollbar-context.js. Added a compile-time case for `<RollbarContext context="/page" />`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: rollbar-circleci-machine <103224042+rollbar-circleci-machine@users.noreply.github.com>
Follow-up to c4ee130, which switched HistoryContextOptions' formatter and filter to method syntax so callbacks annotated with history's own Location/Action types are accepted under strictFunctionTypes. - Re-indent formatter? in index.d.ts (Prettier check failed on it). - types.test-d.tsx: name the v4/v5 Location and Action shapes and add formatter/filter callbacks annotated with them. With property syntax restored, typecheck fails with TS2322 on all four callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests were plain JS only because index.d.ts on main had no `onRender`. Stacked on #162 they type-check as TSX, like the other component tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f40530b to
89957c9
Compare
AI Agent Review LGTM (openai, openai-astra)LGTM. No blocking findings were found. LGTM — no findings. I read the diff and the code it touches in the checkout: Typings now match the runtime
Outside the diff (not findings)
Consumer impact |
Fixes #69. Builds on #157 (now merged).
Why
#69 listed several places where
index.d.tsdisagreed with the implementation:fallbackUIcomplaint was already fixed in fix ErrorBoundary fallbackUI prop type definition #95.historyContextoptions andv4actionoptional.formatterandfilterreceivedlocation: string, but they're called with aLocationobject.{ action: string; filter: ... }, a copy-paste mistake.({ location, action })signature. [SDK-664] Upgrade rollbar to 3.1.0 to clear Dependabot alerts #157's own test had to castas neveron both calls to get past these types.RollbarContext's typings drifted fromsrc/rollbar-context.js:contextwas optional (the component requires it), andonRenderwas missing.index.d.ts, which is how this drift survived for years.What changed
index.d.tsHistoryLocation:pathname,search,hash, optionalstateandkey. It's structural, so history v4 and v5 locations both fit without adding a dependency onhistory.HistoryContextOptions.formatterandfilterreceive(location: HistoryLocation, action: string). They're declared with method syntax, so callbacks annotated withhistory's ownLocation/Actiontypes (v4 or v5) are accepted too.HistoryContextListener, an overloaded callable:(location, action)({ location, action })history.listen(historyContext(rollbar))now type-checks with both majors.RollbarContext:context: stringis now required,onRender?: booleanis added, andchildrenis now optional (children: PropTypes.nodeat runtime).context. Omitting it already failspropTypesat runtime and sets the context toundefined.Type checking
scripts/typecheck.ts, run asnpm run typecheckand added as a CI step before Build.node_modules.tsc --noEmitfails on errors inside rollbar 3's ownindex.d.tsand rrweb's@types/css-font-loading-module(the upstream follow-up noted in [SDK-664] Upgrade rollbar to 3.1.0 to clear Dependabot alerts #157).--skipLibCheckwould skip our ownindex.d.tstoo. A broken import there would silently becomeanyfor consumers, which is exactly whatmain'simport { Callback, Configuration } from 'rollbar'does under rollbar 3.src/tests/types.test-d.tsx: compile-only checks. It isn't collected by Jest.listensignatures of@types/history@4.7.11andhistory@5.3.0.@ts-expect-errorcases that fail if the typings loosen again. These coverhistoryContext,fallbackUIandRollbarContext.src/tests/history-context.test.ts: dropped theas nevercasts. The v4 and v5 listener calls now type-check as written.Validation
Node 20.19, on top of #157's head
1ba8a01:npm run typecheck:10 files, no errorsindex.d.tsrestored,typecheckfails with 11 errors covering every TypeScript types don't match implementation #69 item: the listener shape,locationas a string, unused@ts-expect-errors, andRollbarContext.main'simport Rollbar, { Callback, Configuration } from 'rollbar'restored, it fails withTS2614insideindex.d.ts.tsc --noEmit --skipLibCheckreports that same file as clean.npm run lint -- --max-warnings 0: passnpx jest: 13/13 passing (3 suites)npm run build: passexamples/typescriptagainst the yalc-published build:tsc && vite build: passvitest run: 1/1eslint: passOnly
examples/typescriptwas built locally. The other examples don't usehistoryContextor the TS types ofRollbarContext.Review follow-up
scripts/typecheck.tsnow splitsSourceFile.fileNameon/instead ofpath.sep. TypeScript stores file names with forward slashes on every platform, so on Windows the old split found nonode_modulessegment and dependency errors were reported. Checked with the compiler API: a root name ofC:\repo\node_modules\x\index.d.tsis stored asC:/repo/node_modules/x/index.d.ts.RollbarContextchildrenis now optional. There's a new compile-time case for<RollbarContext context="/page" />: withchildrenrequired again,typecheckfails with TS2769.typecheck,lint --max-warnings 0, Prettier,jest(13/13) andbuildall pass.Review follow-up 2
formatterandfilternow use method syntax (Brian'sc4ee130). UnderstrictFunctionTypes, the old function-typed properties rejected callbacks annotated as(location: Location, action: Action)with history's types. Those annotations are correct because the runtime passes history's location and action through unchanged.f40530bre-indentsformatter?(Prettier failed on it) and adds compile-time cases totypes.test-d.tsxforformatter/filtercallbacks annotated with the history v4 and v5Location/Actiontypes.typecheckfails with TS2322 on all four annotated callbacks.@ts-expect-errorcases (a non-stringformatterreturn,filter(location: string)) still error under method syntax.typecheck(10 files, no errors),lint --max-warnings 0, Prettier,jest(13/13) andbuildall pass.Changelog note: TS users who omit
RollbarContext'scontext, or typeformatter/filterwith a string argument, will get new compile errors. Both cases were already broken at runtime.🤖 Generated with Claude Code