SynthLuvr
SynthLuvr
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
This works great, except in this situation:
function create<T extends number>(code: T): Type<T>
function create(code: number): type.Any {
return type(["===", code]).describe("abc")
}

function inner<T extends number>(code: T) {
const codeType = create(code);
type({codeType})
}
function create<T extends number>(code: T): Type<T>
function create(code: number): type.Any {
return type(["===", code]).describe("abc")
}

function inner<T extends number>(code: T) {
const codeType = create(code);
type({codeType})
}
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
Ok that works. I think it was broken in the past which is why I had to wrap it, but seems to be working now
12 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
I think updating from 2.0.0-rc.12 to 2.0.0-rc.13 is the real problem here, so maybe I'll stick with the older version for now
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
ugh, that creates more problems
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
I really dislike it but the only way I can figure out how to fix the issue is to do this:
const Dummy = type({});
type Dummy = typeof Dummy;
const codeType = ["===", code] as const;
type codeType = typeof codeType;

return {
error: type({
message,
code: (type(["===", code]) as Dummy).describe(
`Always equal to ${code}`,
) as unknown as codeType,
}),
};
const Dummy = type({});
type Dummy = typeof Dummy;
const codeType = ["===", code] as const;
type codeType = typeof codeType;

return {
error: type({
message,
code: (type(["===", code]) as Dummy).describe(
`Always equal to ${code}`,
) as unknown as codeType,
}),
};
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
I'm a bit stuck on this, not sure how to call describe without messing up the types
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
This is annoying, casting doesn't work because it changes the type definition
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Property 'describe' does not exist on type 'instantiateType<inferTupleExpression<...>, {}>'
Casting works
const Dummy = type(["===", 200]);
const create = <T extends number>(code: T) =>
(type(["===", code]) as Dummy).describe("abc") as Type<T>;
const Dummy = type(["===", 200]);
const create = <T extends number>(code: T) =>
(type(["===", code]) as Dummy).describe("abc") as Type<T>;
13 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
Got it
const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s, ctx) => {
const result = Letters(s);
return result instanceof type.errors
? ctx.error(result.at(0)!.expected!)
: result;
});
const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s, ctx) => {
const result = Letters(s);
return result instanceof type.errors
? ctx.error(result.at(0)!.expected!)
: result;
});
12 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
hmm, not quite
12 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
import { type } from "arktype";

const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s) => {
const result = Letters(s);
return result instanceof type.errors ? result.at(0)! : result;
});

console.log(Letter.assert("d"));
import { type } from "arktype";

const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s) => {
const result = Letters(s);
return result instanceof type.errors ? result.at(0)! : result;
});

console.log(Letter.assert("d"));
This seems to produce the same behavior I'm accustomed to:
AggregateError: must be "a", "b" or "c" (was "d")
AggregateError: must be "a", "b" or "c" (was "d")
12 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
ctx.error(result.summary) works, but then duplicates the error AggregateError: must be must be "a", "b" or "c" (was "d") (was "d")
12 replies
Aarktype
Created by SynthLuvr on 9/28/2024 in #questions
Piping types no longer works
import { type } from "arktype";

const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s, ctx) => {
const result = Letters(s);
return result instanceof type.errors ? ctx.error(result) : result;
});

console.log(Letter.assert("d"));
import { type } from "arktype";

const Letters = type("'a'|'b'|'c'");
const Letter = type("string").pipe((s, ctx) => {
const result = Letters(s);
return result instanceof type.errors ? ctx.error(result) : result;
});

console.log(Letter.assert("d"));
Produces:
description: node => `valid according to ${node.predicate.name || "an anonymous predicate"}`
^

TypeError: Cannot read properties of undefined (reading 'name')
description: node => `valid according to ${node.predicate.name || "an anonymous predicate"}`
^

TypeError: Cannot read properties of undefined (reading 'name')
12 replies
Aarktype
Created by SynthLuvr on 9/6/2024 in #questions
Type instantiation is excessively deep and possibly infinite
What would be cool is if we could do type("bigint>0n")
52 replies
Aarktype
Created by SynthLuvr on 9/6/2024 in #questions
Type instantiation is excessively deep and possibly infinite
I'm pretty sure it worked in the past but I don't know when
52 replies
Aarktype
Created by SynthLuvr on 9/4/2024 in #questions
Record with number as key?
Also:
const B = ark.Record("number", "number");
const B = ark.Record("number", "number");
Argument of type '["number", "number"]' is not assignable to parameter of type '["number", "number"] & [ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type '["number", "number"]' is not assignable to type '[ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type 'string' is not assignable to type 'ErrorType<"Invalid argument for K", [expected: Key]>'
Argument of type '["number", "number"]' is not assignable to parameter of type '["number", "number"] & [ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type '["number", "number"]' is not assignable to type '[ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type 'string' is not assignable to type 'ErrorType<"Invalid argument for K", [expected: Key]>'
6 replies
Aarktype
Created by SynthLuvr on 9/2/2024 in #questions
Type instantiation is excessively deep and possibly infinite
For my purposes, I was able to create a workaround:
import { ArkErrors } from "arktype";

// Define a separate AnyType due to:
// https://github.com/arktypeio/arktype/issues/1117
type AnyType<T = unknown> = {
(data: unknown): T | ArkErrors;
describe: (description: string) => AnyType<T>;
description: string;
infer: unknown;
json: unknown;
};

export { AnyType };
import { ArkErrors } from "arktype";

// Define a separate AnyType due to:
// https://github.com/arktypeio/arktype/issues/1117
type AnyType<T = unknown> = {
(data: unknown): T | ArkErrors;
describe: (description: string) => AnyType<T>;
description: string;
infer: unknown;
json: unknown;
};

export { AnyType };
18 replies
Aarktype
Created by SynthLuvr on 9/2/2024 in #questions
Type instantiation is excessively deep and possibly infinite
Argument of type 'Type<(In: string) => Out<string>, {}>' is not assignable to parameter of type 'Any<any>'.
Types of property 'out' are incompatible.
Type 'Type<unknown, {}>' is missing the following properties from type 'Type<any, any>': matching, atLeastLength, atMostLength, moreThanLength, and 2 more.ts(2345)
Argument of type 'Type<(In: string) => Out<string>, {}>' is not assignable to parameter of type 'Any<any>'.
Types of property 'out' are incompatible.
Type 'Type<unknown, {}>' is missing the following properties from type 'Type<any, any>': matching, atLeastLength, atMostLength, moreThanLength, and 2 more.ts(2345)
18 replies
Aarktype
Created by SynthLuvr on 9/2/2024 in #questions
Type instantiation is excessively deep and possibly infinite
For example:
const m = <t extends Type.Any>(type: t): t => type.describe("test");
const a = type("string").pipe((s) => s);
const t = m(a);
const m = <t extends Type.Any>(type: t): t => type.describe("test");
const a = type("string").pipe((s) => s);
const t = m(a);
18 replies
Aarktype
Created by SynthLuvr on 9/2/2024 in #questions
Type instantiation is excessively deep and possibly infinite
grr yeah so now I need to know the type ahead of the call so I can set the correct generic
18 replies