Repository navigation
Replies: 2 comments 1 reply
|
Unfortunately this is the kind of thing that mostly boils down to quirks of complex TS and has to be addressed on a case-by-case basis. I may have some useful intuitions, but I'd need to see a more complete repro to be able to help. The best I can give for dealing with these types in general is to look at how ArkType handles function signature for complex transformations and try to mimic that. |
|
I reproduced the If accepting an already constructed import { ArkErrors, type, type Type } from 'arktype';
const json = type('string.json.parse');
function arkParseJSON<T extends Type<any, any>>(
schema: T,
value: string,
): T['infer'] | ArkErrors {
const parsed = json(value);
return parsed instanceof ArkErrors ? parsed : schema(parsed);
}
const parserFor = <T extends Type<any, any>>(schema: T) =>
(value: string) => arkParseJSON(schema, value);
const parseUser = parserFor(type({ name: 'string', age: 'number' }));
const result = parseUser('{"name":"Ada","age":32}');
if (result instanceof ArkErrors) {
console.log(result.summary);
} else {
const age: number = result.age;
}This changes the API deliberately: call Using the inferred output also preserves morph results: const parseLength = parserFor(type('string').pipe(s => s.length));
const length = parseLength('"abc"'); // number | ArkErrors; success value 3I checked the alternative on both the archive's versions and ArkType 2.2.9 / TypeScript 5.9.3, running under Node 24.22.1. Strict compilation passes, including negative type assertions for object-field and morph-output types. Runtime checks cover the ordinary object, a morph, a type exported from a scope, malformed JSON, wrong property type, The early |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I want to wrap and call a function in the form of
And currying this function.
But I have never been able to resolve these two types of errors.

Current alternative solutions
All reactions