How to type an expressjs-like route handler based on the path pattern.
If I define an application like:
get('/path/:id?q=:query', handler)
is it possible to look at the structure of the string and infer the type of the parameters that are passed to the handler
function as { id: string; query: string;}
. Given the prevalence of this pattern, I'd expect that someone has attempted it before, but I can't seem to find it in the docs and/or discord....Compiling to JavaScript results in `any` type
I have a TypeScript library that compiles down into JavaScript, and one of the ...
d.ts
files looks like this:
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
Was `any` removed?
I used to be able to do:
type("any");
. Now it's throwing error Argument of type '"any"' is not assignable to parameter of type '"'any' is unresolvableā"'
Type instantiation is excessively deep and possibly infinite
const m = <T, U>(type: Type<T, U>) => {
return type.describe("test");
}
const m = <T, U>(type: Type<T, U>) => {
return type.describe("test");
}
Best way to pass `Type` around
Hello! First, thanks for building this really cool library š I first heard of arktype while I was looking at the code of a framework called MUD, and while I was discussing CLI libraries with @frolic the other day, I thought that maybe it'd be a cool idea to have a CLI library that leverages arktype for arguments and options validation/parsing. I basically would like to have a function that receives args that are generated from arktype definitions. This is the code I have so far:
```ts
import { type Type, type, validateAmbient } from "arktype";
import { type ErrorMessage } from "@ark/util";...
Default number
Hello!
Setting this brings the expected result, when ran through
inferAmbient
:
```ts...Optional property with const string array
Hello, the following ...
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
const x = ["a", "b", "c"] as const;
const myType = type({
"optional?": type("===", ...x),
});
Extending types similar to an interface
How would one go about extending types similar to how one would extend an interface in TypeScript? It's really the only thing I feel like is missing for ArkType to be a viable alternative.
A minimal example of what I want for ArkType, but written in TypeScript:
```typescript
interface BaseTitle {...
Indexed Access Types
Hello, is it possible to recreate the
SizeValues
type below in arktype? ```ts
const sizes = [
{ label: "Big", value: "100kg" },
{ label: "Medium", value: "50kg" },
{ label: "Small", value: "10kg" },...vscode intellisense errors on the same type definition in some files, but not others
e.g. the following type:
```ts
const exampleType = type({
email: "string.email",
});...
Accept number in string type
Hello! I'm parsing each value in a form with
JSON.parse
to convert string values like false
to actual booleans. Unfortunately, this introduces the issue, that if someone inputs 123
into a text field, it gets parsed into a number type by JSON.parse
. Then if the field is type string
. An error is thrown, since number is not assignable to string.
How should a type look like, if it should handle such a situation?...Automatically applying parse.integer
Let's say I have a type I'm using to validate some API, e.g.
```
const personSchema = type({
name:'string',
age:'0<=number<=120'...
Extract type from or
Hello! Is it possible, using the following schema:
```ts
const userType = type({
intent: "'profile'",
name: 'string>0',...
Get type without constraints
Hello!
inferAmbient
retuns types with constraints like moreThanLength<0>
, which when I try to access values to, I get Type 'string' is not assignable to type 'moreThanLength<0>'
.
Is it possible to extract a more basic type?...codecs
with morphs, I am thinking of arktype types as sort of input/output functions
for
const t = type(...)
t.allows(input)
tells if you if input is the right shape
t(input)
takes input and turns it into output (or errors)
...How to handle checkbox in type('parse.formData').to(...)
I want turn the checkbox into boolean, but the checkbox field only produce "on" when checked, and missing when unchecked...
Latest "keys:distilled" equivalent?
Hello, I started using ArkType a back in v1 and it has obviously come on leaps and bounds since then which is great to see.
However, back in v1 you could do something like ```ts
export const loginPayload = type(
{...
Error internationalization (i18n)
Hello! Is it possible to translate the errors into other languages?
In my previous setup I was using this for such funtionality:
https://github.com/aiji42/zod-i18n
...