mshafir
mshafir
Aarktype
Created by mshafir on 4/9/2025 in #questions
branded types are not portable when declaration: true
Hi, I'm trying to export a branded type from a shared node package. The tsconfig has declaration: true because I want the type declarations emitted, but that seems to get me a type portability error:
The inferred type of 'Test' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@ark/util'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'Test' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@ark/util'. This is likely not portable. A type annotation is necessary.ts(2742)
just from
import { type } from "arktype";

export const Test = type.string.brand("test");
import { type } from "arktype";

export const Test = type.string.brand("test");
I know it can work if I explicitly type the return, but I don't want to give up type inference, is there an easy solution to this?
2 replies
Aarktype
Created by mshafir on 3/12/2025 in #questions
How to combine multiple configure() calls
I noticed that if I call configure multiple times each next call wipes out the previous metadata. Here's a test example
test("arktype config", () => {
const t = type("string")
.configure({ description: "a test" })
.configure({ alias: "cool" });
expect(t.toJSON()).toMatchInlineSnapshot(`
{
"domain": "string",
"meta": {
"alias": "cool",
},
}
`);
});
test("arktype config", () => {
const t = type("string")
.configure({ description: "a test" })
.configure({ alias: "cool" });
expect(t.toJSON()).toMatchInlineSnapshot(`
{
"domain": "string",
"meta": {
"alias": "cool",
},
}
`);
});
Using .describe() has the same results. Notice that the meta only has the alias, not the description. Is there a way to instead have configure chain the request so it doesn't override prior metadata? I know in theory it could all happen in one configure, but in my codebase there are multiple layers so that in some cases I want to build on another type and just add some metadata to it.
6 replies