Unable to set default on referenced `type.string.matching` when defined within scope
Report a bug
🔎 Search Terms
default string.matching scope
🧩 Context
- ArkType version: 2.1.22
- TypeScript version (5.1+): 5.6.2
- Other context you think may be relevant (JS flavor, OS, etc.):
🧑💻 Repro
Playground Link: https://arktype.io/playground?code=import%2520%257B%2520scope%252C%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Scope%2520%253D%2520scope%28%257B%250A%2520%2520semverWithV%253A%2520type.string%250A%2520%2520%2520%2520.matching%28%252F%255Ev%255Cd%252B%255C.%255Cd%252B%255C.%255Cd%252B%28%253F%253A%255B-%252B%255D%255BA-Za-z0-9.-%255D%252B%29%253F%2524%252F%29%250A%2520%2520%2520%2520.describe%28%27valid%2520version%2520format%2520%28expected%2520vX.Y.Z%29%27%29%252C%250A%2520%2520%2520%2520payload%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520version%253A%2520%2522semverWithV%2520%253D%2520%27v0.0.0%27%2522%250A%2520%2520%2520%2520%257D%250A%257D%29%253B%250A
import { scope, type } from "arktype"
const Scope = scope({
semverWithV: type.string
.matching(/^v\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/)
.describe('valid version format (expected vX.Y.Z)'),
payload: {
version: "semverWithV = 'v0.0.0'"
}
});
Weirdly, it works when the exact same type is defined outside the scope, and then added into the scope:
import { scope, type } from "arktype"
const semverWithV = type.string
.matching(/^v\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/)
.describe('valid version format (expected vX.Y.Z)');
const Scope = scope({
semverWithV,
payload: {
version: "semverWithV = 'v0.0.0'"
}
});