`narrow` vs `satisfying`
Are there docs on how to do non-trivial self reference?
this
keyword, but I'm looking to do something like:
```ts
const example = type({
name: "string",
selves: "this[]",...Some performance struggles
Using scope with morphs
string.json.parse
to read that data in and validate it.
```ts
const UserConfigSchema = scope({
config: type("string.json.parse").to({
// ERROR:...Passing an exported scope to a function (Type 'string' is not assignable to type 'never')
Is there a way to set a default value that is not valid?
""
, not undefined.
I am not sure how to define an Arktype type that accepts only an enum of values from the radio button, but defaults to empty-string. When I do the obvious inputType.default("")
I get errors:
ParseError: Default value is not assignable: must be "enum_option" (was "")
...Union Fallthrough?
Defining and inferring a generic type defined inside a scope
morphing to typescript type
type("string")
to try to parse out a Temporal.ZonedDateTime
type to sort of replicate what type("string.date.iso.parse")
does, and it mostly works. But I've noticed if I infer the TS type I can't actually assign a Temporal.ZoneDateTime
to the field, as tsc complains that the valueOf
signatures are different. Is this supposed to work, or should I be venturing down the path of scopes and rootSchema
instead?
```typescript
const zonedDateTimeISO = type("string")
.narrow((date, ctx) => {...Generic middleware validator
Compiling scope to interfaces
Union of generics
Merging types instead of using an intersection when using generics
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
generic('T', 'M')([ 'T', '&', { metadata: { id: 'M' }} ])
Generic & intersection
arkWithMetadata
, which basically takes a base type and add { metadata: { id: <id> }}
I wanted to write this :
```ts
export const arkWithMetadata = type(
'<doc extends Record<string, unknown>, id extends string>',...Is there a way to morph an optional value back to a required one?
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
const schema = type({
PORT: ['string?', '=>', (v?: string) => parseInt(v ?? '3000')]
})
Generic modules, Enums and AnyOf
OneOf
I suggest making a Enum generic (called OneOf
maybe) that works as following:
- it accepts an object definition O
- it has a root type which allows any of the property values O[keyof O]
- it is a module with all property types as its values, Module<{ [K in keyof O]: Type<O[K]> }>
...Multiple @ark registries detected
Multiple @ark registries detected. This can lead to unexpected behavior.
Multiple @ark registries detected. This can lead to unexpected behavior.
File type
Type definitions must be strings or objects (was undefined)
Type definitions must be strings or objects (was undefined)
. I am not sure what it means. What should I be looking for to solve it?...Function which receives a arktype's 'type'