Skip to content

docs(guides): formula fields declare result type via returnType, not type - #2263

Merged
os-zhuang merged 2 commits into
mainfrom
docs/formula-returntype
Jun 24, 2026
Merged

os-zhuang merged 2 commits into
mainfrom
docs/formula-returntype

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Why

While reviewing the returnType feature (#2255) I found the formula guides teach a broken pattern:

Field.formula({ type: 'currency', expression: F`…` })   // ❌

Field.formula's config is FieldInput = Omit<Partial<Field>, 'type'>, so type is a type error. And untyped (as in an .mdx snippet), the spread { type:'formula', ...config } lets type:'currency' override type:'formula' — and objectql computes a formula virtual field from def.expression only (engine.ts:55, no defaultValue fallback), so the field silently never computes. Some examples also used a formula: key that isn't on FieldSchema (the source key is expression).

So there's no real type/returnType overlap — type simply can't be set on a formula; returnType is the intended mechanism.

Fix

  • All Field.formula examples in formula.mdx + business-logic.mdx: type: X → returnType: <number|text|boolean|date>, formula: → expression:, valid scale preserved.
  • Added a Callout in formula.mdx: a formula field's type is always formula; declare the computed value type with returnType (inferred/stamped by the AI build path); CEL source is expression.

Docs-only; other guides (data-modeling.mdx, metadata/field.mdx) already used the correct pattern.

🤖 Generated with Claude Code

…t `type`

`Field.formula`'s config is `FieldInput = Omit<Partial<Field>, 'type'>`, so
passing `type: 'currency' | 'text' | 'number' | …` is a type error — and untyped
(in an .mdx example) it OVERRIDES `type:'formula'`, which makes objectql skip the
field entirely: the engine computes a formula virtual field from its `expression`
only (engine.ts), so the field silently never evaluates. Several guide examples
taught that broken pattern; some also used a `formula:` key that isn't on
`FieldSchema` (the source key is `expression`).

Fix all examples to declare the computed value's type with `returnType`
(`number`/`text`/`boolean`/`date` — added in framework#2255) and put the CEL
source on `expression`; restore the valid `scale` I had dropped; add a Callout in
formula.mdx explaining a formula field's `type` is always `formula`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 24, 2026 4:52am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation size/s and removed documentation Improvements or additions to documentation labels Jun 24, 2026
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tooling labels Jun 24, 2026
@os-zhuang
os-zhuang merged commit a71692e into main Jun 24, 2026
14 of 15 checks passed
@os-zhuang
os-zhuang deleted the docs/formula-returntype branch June 24, 2026 04:28

This branch was successfully deployed

1 active deployment
Preview — ec1b9625 Deployed Jun 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/s tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant