#Can I constrain the legal values of a string by type?

1 messages · Page 1 of 1 (latest)

astral trout
#

I've been trying to figure out a way to constrain what values can go into a string by type. What I need is still an infinite list, so I can't just use a string enumeration.

I tried using a type guard, and I tried using typed template tags. Neither succeeded.

I'm doing something more complicated than this, but to explain what I want, consider a system containing orders where every order has an order ID of the form "order_12345", where the preface string is always order_ and the number at the end can be arbitrarily large.

Is there a way to make a string type that can defend that at runtime with literal constant assigments?

clear nova
#
type Order = `order_${bigint}`
astral trout
#

i tried that. i guess i screwed it up somehow