template literal/backtick string types e.g. type T = `type-${string}`
I can't see how to do in Ark:
I specifically want compile-time checking.
Tried to drop it in "1:1" style, but this doesn't work as-is:
nor did it work trying to use 'type' as a tagged template:
I did look in the docs but I don't believe it's there yet, and if it's in the tests I didn't spot it
Do I have to set it up as a custom string constraint so it'd be like
const UserId = type('string-userId')
?
IIUC this doesn't get the compile-time checking:
// Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime. email: "string.email",
8 Replies
Ig this is what you're referring to: https://github.com/arktypeio/arktype/issues/491
GitHub
Template literal · Issue #491 · arktypeio/arktype
Would allow the equivalent TS syntax: // inferred as
a${string}z
[] const t = type("a${string}z
[]") Internally should probably compile to a regex.You'd need to use a morph/narrow for now (probably a narrow)
or whatever
Although the inferred type would just be
string
Yeah even if it didn't give me the exact template type I'd still be happy so long as it's a tagged/branded/opaque type that forced the string through a type predicate before use
Opaque / Branded Types in Typescript
Leveling up your compile-time type-checking in Typescript!
hm, this won't work consistently either:
I wonder if ark should allow you to supply/override the type you want it to infer as
e.g. something like
whoo
perfect
thank you
Ohhh yeahhhhh RegEx 🤩