Skip to content

coerceInput ​

Turns what an input element gives into the value a field's schema expects, by the field's kind.

ts
const value = coerceInput(input, field)

Parameters ​

  • input unknown
  • field { kind: ValueKind; itemKind?: ValueKind }: a FieldNode, or anything with its kinds

Explanation ​

KindInputValue
number'' or only spacesundefined
numbera numeric string, '5'5
filea FileListits first file, or undefined
array of filea FileLista list of its files
array of numbernumeric stringsnumbers

Anything else is passed through, and the schema reports it. The adapters' setInput calls it for you.

Returns ​

  • value unknown

Guides ​