Nicolas
Nicolas
Explore posts from servers
Aarktype
Created by Nicolas on 1/19/2025 in #questions
Extract schema inside an array
Hello there, I'm new to ArkType, and I'm hitting an issue that I cannot seem to be able to solve... I'm trying to extract the runtime schema from within an array. Here is a simple example:
const simple = type({
id: 'number',
array: type({
name: 'string',
age: 'number',
}).array(),
});

const array = simple.get('array');
const arrayContent = array.get(0);
const res = arrayContent({ name: 'Rico', age: 25 });
const simple = type({
id: 'number',
array: type({
name: 'string',
age: 'number',
}).array(),
});

const array = simple.get('array');
const arrayContent = array.get(0);
const res = arrayContent({ name: 'Rico', age: 25 });
The type of res is correctly inferred to
const res: {
name: string;
age: number;
} | ArkErrors
const res: {
name: string;
age: number;
} | ArkErrors
However, the last line is always crashing with TypeError: Cannot convert undefined or null to object it seems the runtime schema is not correctly extracted. I know this was referred as an "anti-pattern" in the docs but here I'm trying to build a tool that can generate an openapi spec out of an ArkType definition so I cannot split my type. Any help would be appreciated.
11 replies
TTCTheo's Typesafe Cult
Created by Nicolas on 10/14/2023 in #questions
Disable static generation in Next?
No description
2 replies
TTCTheo's Typesafe Cult
Created by Nicolas on 9/2/2023 in #questions
RSC: Shared layout in different paths
No description
17 replies