New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Excessive stack depth comparing types 'ParseMixedSchema<?, T>' and 'ParseMixedSchema<?, T>'.ts(2321) #53
Comments
Hi @ffxsam and thanks for the issue. Everything seems fine on Can you try defining type Event = ValidatedAPIGatewayProxyEvent<S>
export const handler = Sentry.AWSLambda.wrapHandler<
Event,
APIGatewayProxyResult | undefined
>(... ...or simply, not providing explicitely the generic types to const yourFunc = async (event: ValidatedAPIGatewayProxyEvent<S>) : Promise<APIGatewayProxyResult | undefined> => ...
export const handler = Sentry.AWSLambda.wrapHandler(yourFunc) What version of |
Hey @ThomasAribart, thanks for the reply! You'll have to excuse me, as my TypeScript ability is passable at best. type Event = ValidatedAPIGatewayProxyEvent<S>; This results in an error, Unfortunately, I can't rely on implicit types here. The code for TypeScript was updated, but I reverted it step by step back to version 4.5.2 and the issue still persisted. Then I reverted from |
import { schema } from './schema'
type S = typeof schema |
Thanks, Thomas! I appreciate the help, but unfortunately, I don't have the bandwidth to try to track down what's going on. I'm guessing it's due to some sloppy TypeScript that |
I've been seein the same error in the latest version in https://github.com/feathersjs/feathers/tree/dove/packages/schema. The smallest example I could come up with to reproduce looks like this: class Test<S extends JSONSchema> {
readonly type: FromSchema<S>;
}
const schemaA = {
type: 'object',
additionalProperties: false,
properties: {
name: { type: 'string' }
}
} as const;
const schemaB = {
type: 'object',
additionalProperties: false,
properties: {
name: { type: 'string' }
}
} as const;
const t: Test<typeof schemaB> = new Test<typeof schemaA>(); Maybe that helps, I can try and do some more digging if you think it's worth investigating. |
Oop, I made a duplicate issue here: #56 Filed here because I haven't seen this error on any other codebases aside from when I use json-schema-to-ts But now I'm thinking we have exposed some bug in TypeScript. |
Typescript 4.7, which introduced variance annotations, has been released. I believe variance annotations could help solve this issue. And overall speed up type inference. @ThomasAribart, could you please look into that? |
@daffl @psznm @ffxsam @ericvicenti Indeed, it seems like the variance annotation helps a bit. The smallest example you provided is fixed by declaring I guess it skips the class Test<in out S extends JSONSchema> {
readonly type?: FromSchema<S>;
}
const schemaA = {
type: "object",
additionalProperties: false,
properties: {
name: { type: "string" },
},
} as const;
const schemaB = {
type: "object",
additionalProperties: false,
properties: {
name: { type: "string" },
},
} as const;
// works fine
const test: Test<typeof schemaB> = new Test<typeof schemaA>(); However, I'm not completely sure this fixes the issue ? 🤔 I've found that defining the expected type as the default value of a second generic type is a functioning work-around though: // "out" annotation is welcome but not necessary
class Test<S extends JSONSchema, out T = FromSchema<S>> {
readonly type?: T;
}
const schemaA = {
type: "object",
additionalProperties: false,
properties: {
name: { type: "string" },
},
// this time, you can have different specs between schemas
required: ['name']
} as const;
const schemaB = {
type: "object",
additionalProperties: false,
properties: {
name: { type: "string" },
},
} as const;
// works fine
const test: Test<typeof schemaB> = new Test<typeof schemaA>(); Can you confirm that it work ? Does it close this issue ? |
I think this can be closed. I haven't seen this weirdo error in a while Now I just need to find workarounds for "Type instantiation is excessively deep and possibly infinite" 😤 |
As of version 1.6.5, I now get this error in several places in my code.
Excessive stack depth comparing types 'ParseMixedSchema<?, T>' and 'ParseMixedSchema<?, T>'.ts(2321)
It comes from this:
which I adopted from the Serverless Framework TS template.
I create a JS/JSON API Gateway schema, e.g.:
and pass it to Sentry's
wrapHandler
:This has worked fine up until the latest release.
The text was updated successfully, but these errors were encountered: