Minimal array length - how to?

This page https://arktype.io/docs/objects#arrays says one can use [] > 1 to constrain minimal array length. However, this doesn't work:
import {type} from 'arktype'

export const config$ = type(
{
env: 'string>0'
},
'[] > 1'
)
import {type} from 'arktype'

export const config$ = type(
{
env: 'string>0'
},
'[] > 1'
)
ERROR:
No overload matches this call.
Overload 1 of 3, '(params: `<${string}>`, def: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | ... 25 more ... | "Merge"): Generic<...>', gave the following error.
Argument of type '{ env: string; }' is not assignable to parameter of type '`<${string}>`'.
Overload 2 of 3, '(_0: validateObjectLiteral<{ readonly env: "string>0"; }, {}, bindThis<{ readonly env: "string>0"; }>>, _1: ArgTwoOperator): Type<...>', gave the following error.
Argument of type '"[] > 1"' is not assignable to parameter of type 'ArgTwoOperator'.(2769)
No overload matches this call.
Overload 1 of 3, '(params: `<${string}>`, def: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "Key" | "Record" | "Date" | "Array" | "false" | "never" | "null" | "true" | ... 25 more ... | "Merge"): Generic<...>', gave the following error.
Argument of type '{ env: string; }' is not assignable to parameter of type '`<${string}>`'.
Overload 2 of 3, '(_0: validateObjectLiteral<{ readonly env: "string>0"; }, {}, bindThis<{ readonly env: "string>0"; }>>, _1: ArgTwoOperator): Type<...>', gave the following error.
Argument of type '"[] > 1"' is not assignable to parameter of type 'ArgTwoOperator'.(2769)
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
3 Replies
TizzySaurus
TizzySaurus4mo ago
There should be a .atLeastLength (or similar) that you can use type(obj, '[]').atLeastLength(2)
OnkelTem
OnkelTemOP4mo ago
Thanks @TizzySaurus !

Did you find this page helpful?