Signature
Description
Accepts any array, but doesn’t validate its items further. “poja” means “plain old JavaScript array”, a play onpojo (plain old JavaScript object).
This is a low-level primitive decoder that simply checks if the input is an array. All elements are typed as unknown.
Type
unknown elements, ensuring you can’t accidentally use unvalidated data.
Parameters
None. This is a constant decoder, not a function.Returns
A decoder that accepts any array and returns it typed asunknown[].
Behavior
- Any array: Accepted (empty or non-empty)
- Elements: Not validated, typed as
unknown - Not an array: Decode fails with “Must be an array”
- Array-like objects: Rejected (must be actual arrays)
Examples
Basic Usage
Not Arrays
Type Safety
Building Block for Other Decoders
poja is typically used as a building block for more specific array decoders:
With Transform
With Refine
Chaining to Specific Validators
When to Use
Usepoja when:
- Building custom array decoders
- You need to check if something is an array before further processing
- Creating conditional decoders based on array properties (length, etc.)
- You want to accept any array and validate elements later
When Not to Use
Avoidpoja when:
- You know the element type - use
array(decoder)instead - You need a fixed-length array - use
tuple(...decoders)instead - You don’t actually need array validation - just use TypeScript types
Implementation
Array.isArray() for reliable array detection.
Comparison with Similar Decoders
| Decoder | Elements | Length | Type |
|---|---|---|---|
poja | Not validated | Any | unknown[] |
array(decoder) | Validated with decoder | Any | T[] |
tuple(...decoders) | Each position validated | Fixed | [T1, T2, ...] |
nonEmptyArray(decoder) | Validated with decoder | At least 1 | [T, ...T[]] |
Related Decoders
array- Validates array elements with a decodertuple- Fixed-length arrays with position-specific typespojo- Similar concept for objects
