Skip to content

Fix TypeScript optional row keys#4940

Open
clockwork-labs-bot wants to merge 3 commits intomasterfrom
bot/ts-optional-keys
Open

Fix TypeScript optional row keys#4940
clockwork-labs-bot wants to merge 3 commits intomasterfrom
bot/ts-optional-keys

Conversation

@clockwork-labs-bot
Copy link
Copy Markdown
Collaborator

Summary

Fix TypeScript row inference so .optional() fields become optional object keys instead of required keys whose values may be undefined.

This addresses the reducer/view parameter typing issue from #4516, where callers had to explicitly pass undefined for omitted optional fields.

This is a fresh bot-owned replacement for stalled PR #4518.

Changes

  • split inferred row keys into required and optional keys in InferTypeOfRow
  • add a regression type test proving omitted optional fields typecheck
  • switch package typecheck to direct tsc over the .test-d.ts coverage
  • loosen internal view function storage typing to avoid internal assignability fallout
  • adjust internal table_cache indexing to satisfy the stricter inferred row shape

Example

Before:

await conn.reducers.updateCategory({
  id: BigInt(1),
  name: 'updated category name',
  buttonText: undefined,
  headerText: undefined,
  deleted: undefined,
});

After:

await conn.reducers.updateCategory({
  id: BigInt(1),
  name: 'updated category name',
});

Closes #4516.

Validation

  • pnpm test:typecheck
  • pnpm test

Comment thread crates/bindings-typescript/package.json Outdated
Comment thread crates/bindings-typescript/tsconfig.typecheck.json Outdated
Comment thread crates/bindings-typescript/vitest.config.ts Outdated
@clockwork-labs-bot
Copy link
Copy Markdown
Collaborator Author

Following up on the latest review comments here: you were right that the previous typecheck coverage should not have been narrowed away.

I pushed 7ddb11c67, which does three things:

  • restores the old tsconfig.typecheck.json coverage
  • restores the old Vitest typecheck include set
  • adds a separate tsconfig.typecheck.dts.json pass for the new .test-d.ts regression coverage

So the new coverage is additive now, not a replacement. Local pnpm test:typecheck, pnpm test, and pnpm format all passed on that follow-up.

@bfops
Copy link
Copy Markdown
Collaborator

bfops commented May 4, 2026

I think this should have some kind of smoketest for some of the code that used to fail. And it should be reviewed by someone who is more familiar with this part of the code. It seems generally good though.

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.

Typescript optional values should also be "key optional"

2 participants