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");
}
This used to work for me in in 2.0.0-dev.29. But upgrading to 2.0.0-rc.5 I get:
Type instantiation is excessively deep and possibly infinite.ts(2589)
(method) Type<out t = unknown, $ = {}>.describe(description: string): Type<T, U> | Type<T, U>
Type instantiation is excessively deep and possibly infinite.ts(2589)
(method) Type<out t = unknown, $ = {}>.describe(description: string): Type<T, U> | Type<T, U>
6 Replies
ssalbdivad
ssalbdivad3mo ago
Describe doesn't change the underlying type why not just:
const m = <t extends Type.Any>(type: t): t => {
return type.describe("test");
}
const m = <t extends Type.Any>(type: t): t => {
return type.describe("test");
}
In general when it comes to this kind of stuff relying on TS to calculate your generic returns is not a good idea. If you're creating wrapper functions, you'll want to manually annotate the return type, even if it seems to work fine with TS directly because of nonsense like that I can't test for
SynthLuvr
SynthLuvrOP3mo ago
Ok I'll try This isn't working for my use case unfortunately
Found 188 errors in 49 files.
Found 188 errors in 49 files.
ssalbdivad
ssalbdivad3mo ago
That doesn't make any sense just cast the return to never
const m = <t extends Type.Any>(type: t): t => {
return type.describe("test") as never;
}
const m = <t extends Type.Any>(type: t): t => {
return type.describe("test") as never;
}
SynthLuvr
SynthLuvrOP3mo ago
It now seems to be infering as Type.Any for the generic parameter So that's causing me a ton of problems grr yeah so now I need to know the type ahead of the call so I can set the correct generic 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);
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)
ssalbdivad
ssalbdivad3mo ago
Oh that sucks Ideally Type.Any would allow any type I think it is related to the recent changes that allow the methods chained off Type to be specific to what is inferred You can open an issue "all types should be assignable to Type.any" with a repro like this:
const tt: Type.Any = {} as Type<(In: string) => Out<string>, {}>
const tt: Type.Any = {} as Type<(In: string) => Out<string>, {}>
SynthLuvr
SynthLuvrOP3mo ago
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 };
Want results from more Discord servers?
Add your server