Skip to content

refactor: port to native ts - #484

Draft
toomuchdesign wants to merge 12 commits into
masterfrom
port-to-native-ts
Draft

refactor: port to native ts#484
toomuchdesign wants to merge 12 commits into
masterfrom
port-to-native-ts

Conversation

@toomuchdesign

Copy link
Copy Markdown
Owner

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:

  • Tests for the changes have been added
  • Docs have been added / updated

Andrea Carraro and others added 12 commits June 2, 2026 15:59
…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-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5402c0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
re-reselect Major

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

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.

1 participant