Skip to content

Fix coercion through schema unions and type references#2711

Merged
datduyng merged 2 commits into
mainfrom
domnguyen/fix-schema-union-coercion
Jul 21, 2026
Merged

Fix coercion through schema unions and type references#2711
datduyng merged 2 commits into
mainfrom
domnguyen/fix-schema-union-coercion

Conversation

@datduyng

@datduyng datduyng commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

editorPosition is declared as EditorPosition | number. The input "1" can be coerced to 1, but union/type-reference validation discarded that result and left the original string for later validation.

This is an inconsistent experience because in https://github.com/microsoft/TypeAgent/blob/15ef5aa0362e3296bd9d6bd2f001fab704375d27/ts/packages/actionSchema/src/validate.ts

we explicitly allowed casting string to number but not at the stored value level.

> @action code splitEditor --parameters {"editorPosition":"1","direction":"down"}

Input:  editorPosition = "1" (string)
Schema: EditorPosition | number

Before:
  number branch -> 1 (number)
  stored value  -> "1" (string)
  output        -> Action parameter type mismatch editorPosition: value doesn't match any of the union type

After:
  number branch -> 1 (number)
  stored value  -> 1 (number)
  output        -> Split editor (1) down

The fix returns coerced values through union and type-reference wrappers so the parent object stores the declared type.

pr-2711-before-after.mp4

- Return coerced primitive values from successful union branches.

- Preserve coercion through resolved type references and nested containers.

- Add regression coverage for direct, object, and array values.
@datduyng
datduyng marked this pull request as draft July 21, 2026 05:25
@datduyng
datduyng marked this pull request as ready for review July 21, 2026 20:32
@datduyng
datduyng enabled auto-merge July 21, 2026 20:56
@datduyng
datduyng added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit 3aef73b Jul 21, 2026
27 checks passed
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