Skip to content

Provide a clear example of a default variable for an array #163

@yamcodes

Description

@yamcodes

This doesn't work in ArkEnv (and ArkType):

Image

Based on the docs we should use pipes:

https://arktype.io/docs/objects#properties-defaultable

But this is not clearly possible with ArkEnv (See #162)

Also, based on this, you would expect this to work:

import arkenv, { type } from "arkenv";

const Thing = arkenv({
	array: type("number.integer[]").default(() => []),
});

Instead, we are getting:

Type '[Type<number[], { string: Submodule<{ root: string; " arkInferred": string; trim: Submodule<$ & { " arkInferred": (In: string) => To<string>; }>; normalize: Submodule<$ & { " arkInferred": (In: string) => To<...>; }>; ... 19 more ...; host: string; }>; number: Submodule<...>; }>, "=", () => never[]]' is not assignable to type 'string'.ts(2322)

I think that createEnv is defined in a way that does not allow an internal type, and the issue is probably not in the type we export since this works:

import arkenv, { type } from "arkenv";

const Thing = type({
	array: type("number.integer[]").default(() => []),
});

More specifically the signature (i/o) of the createEnv function is probably insufficient.

Metadata

Metadata

Assignees

Labels

arkenvChanges to the `arkenv` npm package.exampleIssues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions