exact length "string = 2"

Can we do something like stateCode: 'string.alpha = 2' ? stateCode: type.string.exactlyLength(2), works but curious if the = works
7 Replies
BozoWithTheBanjo
import { type } from 'arktype';

const x = type({
stateCode: '1 < string.alpha < 3',
});

const out = x({ stateCode: 'Error' });

if (out instanceof type.errors) {
console.error(out.summary);
}
// error is: stateCode must be exactly length 2 (was 5)
import { type } from 'arktype';

const x = type({
stateCode: '1 < string.alpha < 3',
});

const out = x({ stateCode: 'Error' });

if (out instanceof type.errors) {
console.error(out.summary);
}
// error is: stateCode must be exactly length 2 (was 5)
maybe something like this I think using = is assigning default value there
Dimava
Dimava4mo ago
= means default So here you need 2<=string.alpha<=2
DiamondDragon
DiamondDragonOP4mo ago
I see. Maybe a “===“ alias would make sense here
Dimava
Dimava4mo ago
Maybe it's there and we've just not tried it lol So It was there all the time
DiamondDragon
DiamondDragonOP4mo ago
Wait you mean ===?
Dimava
Dimava4mo ago
import { type } from 'arktype'

type("string == 123")
import { type } from 'arktype'

type("string == 123")
no ==
DiamondDragon
DiamondDragonOP4mo ago
Oh cool. Yeah I’ve only begun exploring the lib today

Did you find this page helpful?