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
Excessive stack depth comparing types #505
Comments
Hello, I'll need the full api declaration to trouble shoot what is hapenning |
Hi ecyrbe, I need some time to look over the API spec and see if there's anything we don't want to make public. The error is so sporadic that I'm unable to reliably reproduce it. 😕 General question: My API has "only" 55 endpoints and VSCode is feeling quite sluggish already on my M1 Macbook Pro. Is it normal that TS checking takes about 2-3 seconds now with Zodios? Typechecking was almost instantly before introducing it. Thanks a lot for any help and this awesome library! |
Can you try to update to latest version, i also found ts perf issues with 10.9.2 , 10.9.4 got it back to better perfs. |
The new version caused even longer delays (10+ seconds) during autocompletion and type hovering with TS eventually just giving up, sometimes showing sporadic and indeterministic errors (excessively deep types, circular references and such). Because I tested my API declaration in isolation and couldn't find any problems regarding type checking (it's in a separate package), I went ahead and replaced the middleware types in my backend package with // export type Method = ZodiosMethod;
// export type ZodiosPaths<M extends Method> = ZodiosPathsByMethod<Api, M>;
// export type Middleware<M extends Method, Path extends ZodiosPaths<M>> = ZodiosRequestHandler<
// Api,
// Context,
// M,
// Path
// >;
export type Middleware = any;
export type MyAppRequestHandler = any; // ZodiosRouterContextRequestHandler<Context>;
export type MyAppRequest = any; // WithZodiosContext<Request, Context>; Although my middlewares are now screaming with type errors, this seems to have fixed the problem and TS started working again. Even the autocomplete performance went back to normal territory. So I guess something inside the middleware types must be causing a circular reference or similar thing. Any other ideas? Thanks again for debugging this with me! |
For now, I any-typed my (route-specific) middlewares to get my application up and running again: export const myMiddleware = () => (req: any, res: any, next: any) => {
// ...
} This fixes all TS hickups and performance issues. It's not a big deal at the moment, because I have only a handful of (route-specific) middlewares which are quite small. All global (app-specific) middlewares are correctly typed as follows and don't seem to cause any trouble: export type MyAppRequestHandler = ZodiosRouterContextRequestHandler<MyAppContext>;
export const checkAuth = (): MyAppRequestHandler => async (req, res, next) => {
// ...
} Nevertheless, it'd still be cool if we figured out what causes the TS compiler to run in circles when properly typing route-specific middlewares. ❤️ |
@ecyrbe We're now seeing (probably) similar problems in the frontend since introducing zodios.getKeyByAlias('user', { params: { uuid: userUUID } }), Adding just this single line to our code base wreaks havoc on TS Intellisense. It now takes 10+ seconds and type-checking our frontend React code with The backend and API declaration package type-check just fine. I have put together a minimal reproduction repository and invited you to collaborate. |
Interestingly, the problem is non-existent when using zodios.getKeyByPath('get', '/users/:uuid', { params: { uuid: userUUID } }), |
I was able to reproduce the excessive type instantiation problem we were having in our express backend as well. I added a simple reproduction in the repository I shared with you. |
thank you, will take a look |
FWIW, even after getting rid of all route-specific middlewares I'm still seeing this sporadically:
Just ran into this again immediately after opening my project in VS Code. Restarting TS server made it go away. |
@ecyrbe May I kindly ask if you've had a chance to take a look at this yet? |
Any news on this one, @ecyrbe? Thanks! |
No solution at the moment. |
Thank you! Were you able to reproduce the issue and we can consider it a bug? Or do you need more time to investigate this further? |
i think it's a bug, so i'll let it open until fixed |
Hey @ecyrbe, please don't take the following the wrong way: You've been cranking out release after release over the year and now there hasn't been much activity on the Zodios repository for almost two months. If my memory serves correctly, you've had plans to release v11 at the end of August, but for whatever reasons that didn't work out (no offense, I'm absolutely cool with v10, maybe except for the bug discussed in this issue). After having just migrated a rather big internal application to Zodios, I'm getting somewhat nervous that you're thinking of abandoning the project. Maybe you could be so kind to let us know what the next milestones for the project are going to be? That'd definitely give me (and maybe others) some peace of mind. If you're just taking some time out that's perfectly understandable! 😉 Again, I'm not complaining! I know that it takes a lot of time and hard work to maintain a library like Zodios and I'm absolutely thankful for all the work you've put into it so far! It has made my life as an app developer much easier. Merci beaucoup! 🙏 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please reopen, @ecyrbe. Thanks! |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump |
Not sure if related, but also facing performance issues when using import { mock, type MockProxy } from 'vitest-mock-extended';
const mockAccountsClient: MockProxy<AccountsClient> = mock();
// ^ TypeScript. Type instantiation is excessively deep and possibly infinite The Here is the API definition for this client: https://gist.github.com/toteto/61d651541f8e93e27f4891ebbac33ea1 Previously was OK, but adding the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
bump |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
bump |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I have a middleware in which I'm trying to pass the Zodios express request object to a function:
TypeScript is giving me an error though:
I have the feeling that something's generally off with my API declaration or middleware because everything seems to work as expected, but while editing code I'm seeing intermittent type errors as well which go away when restarting the TS server in VSCode:
The second error points to
ZodiosRequestHandler
in mytype Middleware
declaration in the example above.Thanks a lot!
The text was updated successfully, but these errors were encountered: