Skip to content

feat: accept unit-literal array defaults in string syntax - #1662

Open
yamcodes wants to merge 5 commits into
arktypeio:mainfrom
yamcodes:cursor/array-literal-defaults-f080
Open

yamcodes wants to merge 5 commits into
arktypeio:mainfrom
yamcodes:cursor/array-literal-defaults-f080

Conversation

@yamcodes

@yamcodes yamcodes commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1661

Summary

Allow a unit-literal array after = in string syntax, with either quote style:

type({ HOSTS: "string[] = ['localhost']" })
type({ HOSTS: 'string[] = ["localhost"]' })
type({ ports: "number[] = [3000, 8080]" })

Each traversal gets a fresh array, the same way = [] does. Computed defaults stay on the tuple form (["string[]", "=", () => ["localhost"]]).

Checklist

  • Tests added in ark/type/__tests__/objects/defaults.test.ts
  • Rebased onto current main
  • Package build typecheck passes (pnpm -r --filter !@ark/docs build), which is what the core check failed on
  • Full pnpm prChecks was not run locally; CI still runs lint, tests, and benches

cursoragent and others added 2 commits September 25, 2026 13:31
Parse lists like `string[] = ['localhost']` and `number[] = [3000, 8080]` as fresh-array thunks, matching `= []`.

Co-authored-by: Yam Borodetsky <hi@yam.codes>
The package build rejects an unnarrowed quote token and a root that has not been checked as a unit.

Co-authored-by: Yam Borodetsky <hi@yam.codes>
@cursor
cursor Bot force-pushed the cursor/array-literal-defaults-f080 branch from 58661be to 932a786 Compare September 25, 2026 13:32

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

A unit-literal array default followed by trailing whitespace loses its type-level default value — the reconstructed literal collapses to never.

Reviewed changes

  • Unit-literal array defaults — parseDefault now recognizes [...] after =, parsing each element as a unit literal at runtime (parseUnitLiteralArray/parseUnitLiteralElement) and mirroring the same grammar at the type level, then returning a fresh-array thunk like [] does (with Date elements cloned per traversal).
  • Tests — 11 new cases in objects/defaults.test.ts covering both quote styles, interior whitespace and trailing commas, fresh-array semantics, and rejection of non-literal elements, unassignable elements, non-array bases, and trailing junk.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread ark/type/parser/shift/operator/default.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Delta is clean — no new issues since the prior review.

Reviewed changes (since the prior review)

  • enclosedUnit helper — factors the parseEnclosed call plus a hasKind("unit") guard out of both the quoted-string and d'/d" element branches of parseUnitLiteralElement. Behavior is unchanged (valid literals always produce a unit node, so the guard never fires) and it resolves the build typecheck that previously read .unit off an unnarrowed BaseRoot.

The trailing-whitespace finding from the previous review is not touched by this commit and remains open.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Trailing spaces after the closing bracket were part of the stored literal, so the type collapsed to never while runtime still accepted the default.

Co-authored-by: Yam Borodetsky <hi@yam.codes>
@yamcodes

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Two inputs the runtime parser accepts are rejected at the type level — date elements and numeric tokens that JS rounds. Both are detailed inline.

Reviewed changes

  • Unit-literal array defaults — parseDefault now recognizes [...] after = in string definitions, parsing each element as a unit literal at runtime (parseUnitLiteralArray/parseUnitLiteralElement) and mirroring the grammar at the type level (parseUnitLiteralArray/parseUnitElement), then returning a fresh-array thunk like [] does (with Date elements cloned per traversal).
  • Trailing-whitespace fix — the latest commit routes the type-level branch through Scanner.skipWhitespace/trim so = ['a'] no longer collapses the default type to never; the prior review's finding is addressed.
  • Tests — 11 new cases in ark/type/__tests__/objects/defaults.test.ts covering both quote styles, interior whitespace and trailing commas, fresh-array semantics, and rejection of non-literal/unassignable elements, non-array bases, and trailing junk.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread ark/type/parser/shift/operator/default.ts Outdated
Comment thread ark/type/parser/shift/operator/default.ts Outdated
Date prefixes were parsed as plain strings, and numbers JavaScript cannot represent exactly were rejected even though the runtime accepts them.

Co-authored-by: Yam Borodetsky <hi@yam.codes>
@yamcodes

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No blocking issues — both prior findings are fixed. Two minor follow-ups below.

Reviewed changes (delta against the prior pullfrog review)

  • Date elements now reachable at the type level — parseUnitElement matches the d'/d" prefix before the generic quote branch, so Date[] = [d'2020-01-01'] resolves to Default<Date[], [Date]> instead of never.
  • Inexact numbers infer as number — the number extends n ? never guard was dropped from inferUnenclosedElement, so tokens JS rounds (e.g. 9007199254740993) infer number, matching the runtime and the scalar default path.
  • Tests — added "array default accepts date elements" and "array default accepts a number that is not an exact literal".

ℹ️ String-syntax docs still describe only empty collection defaults

ark/docs/content/docs/objects/index.mdx:167 states "An empty array or object can be defaulted directly in string syntax" and shows only = [] / = {}. With non-empty unit-literal arrays now supported, that paragraph and its example are incomplete. Note that a docs edit also requires regenerating ark/docs/public/llms.txt.

Technical details
# Document non-empty array defaults in string syntax

## Affected sites
- `ark/docs/content/docs/objects/index.mdx:167-175` — prose and example cover only `= []` / `= {}`.
- `ark/docs/public/llms.txt` — generated from docs `.mdx` files by `writeLlmsTxt()`; must be regenerated after any docs-content edit.

## Required outcome
- The string-syntax defaults paragraph/example should mention that `= ['a']` / `= [1, 2]` are accepted and produce a fresh array per traversal.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread ark/type/parser/shift/operator/default.ts
The objects page only described empty `= []` and `= {}` defaults.

Co-authored-by: Yam Borodetsky <hi@yam.codes>
@yamcodes

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (delta since the prior pullfrog review)

The only commit since the prior pullfrog review (ff9033c6) is the docs update, so I re-verified the full feature at head rather than only the docs.

  • Docs updated — ark/docs/content/docs/objects/index.mdx and its generated ark/docs/public/llms.txt now describe unit-literal array defaults alongside the empty-collection forms, with hosts/ports examples, resolving the prior review's open docs finding.

I confirmed the committed llms.txt is exactly what writeLlmsTxt() regenerates, and spot-checked type/runtime parity for bigint, escaped-quote, bracket-in-string, undefined, negative-number, and nested-array (rejected) elements — all consistent with the scalar path.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

Allow non-empty array literal defaults in string syntax

2 participants