Skip to content

fix: extend fix-types.mjs to process all generated d.ts files for consistent declarations#8501

Draft
Copilot wants to merge 6 commits into
masterfrom
copilot/fix-issue-8488
Draft

fix: extend fix-types.mjs to process all generated d.ts files for consistent declarations#8501
Copilot wants to merge 6 commits into
masterfrom
copilot/fix-issue-8488

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Problem

scripts/fix-types.mjs previously only converted bare .ts import specifiers to .d.ts in dist/types/index.d.ts. All other generated .d.ts files (e.g. rx-document.d.ts, rx-collection.d.ts, rx-query.d.ts, and all plugin declaration files) still contained unresolvable .ts extension imports such as:

// In dist/types/rx-document.d.ts
readonly primaryPath: import("./index.ts").StringKeys<{...}>
// In dist/types/rx-collection.d.ts
import { DocumentCache } from './doc-cache.ts';
// In dist/types/rx-query.d.ts
import { RxQuerySingleResult } from './rx-query-single-result.ts';

When consumers use moduleResolution: "bundler" (the default for Angular 20+), TypeScript resolves .ts extension specifiers exactly — it does not fall back to .d.ts. These broken specifiers cause the referenced types to degrade to any/unknown, which is how Angular template type checker loses the Signal<T> type for $$ and field$$ reactive properties.

Fix

Extended scripts/fix-types.mjs to:

  • Recursively collect all generated .d.ts files under dist/types/
  • Exclude the hand-written dist/types/types/ subdirectory (which already uses correct .d.ts specifiers)
  • Apply the existing .ts.d.ts conversion to every collected file
  • Keep // @ts-nocheck only on dist/types/index.d.ts (as before)

Updated the Angular example to demonstrate and verify correct Signal typing with AngularSignalReactivityLambda:

  • examples/angular/src/app/RxDB.d.ts — switched from Signal<unknown> to AngularSignalReactivityLambda so doc.field$$ resolves to Signal<FieldType> instead of Signal<unknown>
  • examples/angular/src/app/services/database.service.ts — passes AngularSignalReactivityLambda as the Reactivity generic to createRxDatabase
  • examples/angular/src/app/components/heroes-list/heroes-list.component.tsheroCount$$ is now typed as Signal<number>
  • examples/angular/src/app/typings-test.ts (new) — type-check file asserting that doc.name$$Signal<string>, doc.hp$$Signal<number>, count().$$Signal<number>, find().$$Signal<RxHeroDocument[]>, etc.
  • examples/angular/tsconfig.json — enabled strictTemplates: true (replaces fullTemplateTypeCheck) so Angular's template type checker enforces strict typing in component templates
  • test/typings.test.ts — added #8488 AngularSignalReactivityLambda test with explicit Signal<T> type assertions, verified by npm run test:typings

Verification

  • npm run lint — passes
  • npm run check-types — no errors in src/
  • npm run build — succeeds
  • npm run test:fast:memory — 1353 tests passing
  • npm run test:typings — passes with new Angular Signal type assertions

Copilot AI and others added 2 commits May 12, 2026 09:38
Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/6d652866-26e5-47b0-bb5b-49279b0ceb90

Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
@pubkey
Copy link
Copy Markdown
Owner

pubkey commented May 12, 2026

@copilot extend the angular example to test for the correctness

Copilot AI and others added 2 commits May 12, 2026 09:51
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot extend the angular example to test for the correctness

Done in commit aca603b. The angular example now:

  1. RxDB.d.ts — uses AngularSignalReactivityLambda instead of Signal<unknown>, so doc.name$$ resolves to Signal<string>, doc.hp$$ to Signal<number>, etc.
  2. database.service.ts — passes AngularSignalReactivityLambda as the 4th generic to createRxDatabase<..., ..., ..., AngularSignalReactivityLambda>
  3. heroes-list.component.tsheroCount$$ is now typed as Signal<number> (was Signal<unknown>)
  4. src/app/typings-test.ts (new) — type-check file that asserts the correctness of all Signal types:
    • doc.name$$Signal<string>
    • doc.hp$$Signal<number>
    • doc.deleted$$Signal<boolean>
    • collection.count().$$Signal<number>
    • collection.find().$$Signal<RxHeroDocument[]>

Additionally, added an #8488 AngularSignalReactivityLambda test in test/typings.test.ts (verified clean by npm run test:typings) that explicitly checks all these Signal types are correct.

Copilot finished work on behalf of pubkey May 12, 2026 09:54
@pubkey
Copy link
Copy Markdown
Owner

pubkey commented May 12, 2026

@copilot can we also set strictTemplates: true in the angular example?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot can we also set strictTemplates: true in the angular example?

Done in commit df28ca2. Added strictTemplates: true to angularCompilerOptions in examples/angular/tsconfig.json, replacing the less strict fullTemplateTypeCheck.

Copilot finished work on behalf of pubkey May 12, 2026 12:29
@pubkey
Copy link
Copy Markdown
Owner

pubkey commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot ci fails https://github.com/pubkey/rxdb/actions/runs/25734394241/job/75567425148?pr=8501

Fixed in commit cf1182e. The CI failure was TS2846 ("A declaration file cannot be imported without 'import type'") triggered by strictTemplates: true. The root cause was that our previous approach converted .ts.d.ts in import specifiers, but Angular's strict mode disallows directly referencing .d.ts files in imports.

The correct fix (as TypeScript itself suggests in the error message) is to use .js extensions instead. TypeScript with moduleResolution: "bundler" strips .js when resolving imports from within .d.ts files and automatically finds the companion .d.ts file. This avoids TS2846 without needing export type * (which would have broken value exports).

Also removed the broken types/ subdirectory exclusion — there was a path comparison bug (relative vs absolute) that made it ineffective. All .d.ts files under dist/types/ are now processed.

Copilot finished work on behalf of pubkey May 12, 2026 13:23
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