refactor: port to native ts - #484
Draft
toomuchdesign wants to merge 12 commits into
Draft
Conversation
…ping Replaces the 4,465-line hand-written src/index.d.ts and all .js source files with .ts sources that emit declarations via the compiler. Adopts reselect v5's typing strategy: a single `CreateCachedSelectorFunction` interface with three overloads (variadic, variadic+options, array+options) using tuple inference via `[...InputSelectors, combiner: Combiner<...>]`, replacing the per-arity 1..12 hand-written overload duplication. `OutputCachedSelector<InputSelectors, Result>` now extends reselect's `OutputSelector` directly and reuses its `Combiner`, `GetStateFromSelectors`, `GetParamsFromSelectors`, `SelectorArray`, and `CreateSelectorOptions` helpers. The user-facing `keySelector` callback now infers precise parameter types from the input selectors (`(state, user) => ...` correctly types `user`), while the exposed `.keySelector` field keeps the loose `KeySelector<State>` shape for back-compat. Cache classes implement a shared `ICacheObject` interface (`any` keys to match the prior contract). `*ObjectCache` classes narrow keys to `string | number`; sized caches now require a `cacheSize` option. Note: `npm run build` is temporarily broken at this commit (rollup+babel cannot read .ts); the next commit swaps the build tool to tsdown. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Swaps the bundling pipeline from rollup + @rollup/plugin-babel + @babel/preset-env + rollup-plugin-copy + rimraf to tsdown, which natively handles TypeScript compilation, declaration emission, and CJS/ESM/UMD output in a single pass (powered by rolldown). Three separate tsdown configs are run sequentially to preserve the prior dist layout: - dist/es/ : ESM bundle + .d.ts (entry: index, reselectWrapper) - dist/cjs/ : CJS bundle (entry: index, reselectWrapper) - dist/umd/ : UMD bundle (entry: index) The hand-written .d.ts at dist/types/index.d.ts is no longer copied; the canonical declarations live at dist/es/index.d.ts (`types` field in package.json updated accordingly). dist/es/index.d.ts is 168 lines vs the prior 4,464-line hand-written file. The UMD bundle filename is `index.umd.js` (tsdown hardcodes the format suffix for `umd` and `iife`). package.json `browser` updated to match. Removed devDependencies: rollup, @rollup/plugin-babel, @babel/preset-env, rollup-plugin-copy, rimraf. Added: tsdown. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The UMD bundle is now emitted as `dist/umd/index.umd.js` (tsdown hardcodes the `.umd` suffix); update the snapshot test's read path accordingly. The snapshot itself is regenerated because the bundled output now comes from rolldown + oxc (via tsdown) rather than rollup + babel preset-env, producing different (but semantically equivalent) code. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The 10-input-selector test mixes annotated and unannotated `(state) => state.foo` selectors. Reselect v5's stricter inference may require the unannotated selectors to be explicitly typed for the inner `expectTypeOf` assertions to resolve. Runtime behavior is unaffected; this is a type-only follow-up to be addressed in a separate test-update pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirror reselect's withTypes API to create a pre-typed selector creator, letting consumers set the state type once instead of annotating it on every input selector. withTypes only refines static types and returns the same creator at runtime. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Split the public `CreateCachedSelector` interface so the runtime impl can be typed against the callable-only shape (`CreateCachedSelectorImpl`) without inheriting the type-only `withTypes` refinement — `Omit<I, 'withTypes'>` strips call signatures and can't extract the callable-only shape after the fact. Type the impl against `CreateCachedSelectorImpl` directly, narrow `polymorphicOptions` to `PolymorphicCachedOptions` instead of `unknown`, and replace `as` casts with narrowly-scoped `// @ts-expect-error` directives at the boundaries between the public typed surface and the impl's variadic/spread runtime calling convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 5402c0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Refactor
What is the current behaviour? (You can also link to an open issue here)
Types are shipped as a manually crafted file.
What is the new behaviour?
Port the whole package to native TS.
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
TBD
Other information:
Please check if the PR fulfills these requirements: