docs(guides): formula fields declare result type via returnType, not type#2263
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Why
While reviewing the
returnTypefeature (#2255) I found the formula guides teach a broken pattern:Field.formula's config isFieldInput = Omit<Partial<Field>, 'type'>, sotypeis a type error. And untyped (as in an .mdx snippet), the spread{ type:'formula', ...config }letstype:'currency'overridetype:'formula'— and objectql computes a formula virtual field fromdef.expressiononly (engine.ts:55, nodefaultValuefallback), so the field silently never computes. Some examples also used aformula:key that isn't onFieldSchema(the source key isexpression).So there's no real
type/returnTypeoverlap —typesimply can't be set on a formula;returnTypeis the intended mechanism.Fix
Field.formulaexamples informula.mdx+business-logic.mdx:type: X→returnType: <number|text|boolean|date>,formula:→expression:, validscalepreserved.formula.mdx: a formula field'stypeis alwaysformula; declare the computed value type withreturnType(inferred/stamped by the AI build path); CEL source isexpression.Docs-only; other guides (
data-modeling.mdx,metadata/field.mdx) already used the correct pattern.🤖 Generated with Claude Code