ts-rest: Basic example with express: Typescript fails with `Type instantiation is excessively deep and possibly infinite`
Hi friends, I am exploring ts-rest and hope not to use Zod directly, as I use io-ts for a lot of similar typing work. I am following the quickstart and have installed Zod as a dev dependency. Here are my relevant versions:
"dependencies": {
"@ts-rest/core": "^3.30.2",
"@ts-rest/express": "^3.30.2",
"express": "^4.18.2"
},
"devDependencies": {
"@types/express": "^4.17.17",
"typescript": "^4.9.5",
"zod": "^3.22.2"
},
However, when I contrive this basic example contract and server:
// contract.ts
const c = initContract()
export const contract = c.router({
getInfo: {
method: 'GET',
path: '/info',
responses: {
200: c.type<ApiInfo>(),
},
summary: 'Get information about this Docmaps API server',
},
})
// server.ts
const s = initServer()
const router = s.router(contract, {
getInfo: async () => {
const info = api.get_info()
return {
status: 200,
body: info,
}
},
})
createExpressEndpoints(contract, router, app) // <---- ERROR
I get this error on typescript compilation: Type instantiation is excessively deep and possibly infinite. typescript (2589)
Apparently this is an issue that occurs in certain uses of Zod, but since I don’t invoke Zod, i expect this might be an issue with how ts-rest calls Zod.
Can you help me understand if there is a known workaround for it while using ts-rest?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (2 by maintainers)
Thanks @Irelynx and @Talent30 . I also can confirm that downgrading Zod did not help, but downgrading @ts-rest/core to 3.28.0 did prevent the error. The version of
@ts-rest/expressdoes not appear to matter in either case.I had a similar issue, but on the client side. I’m using a monorepo and share the contract in a separate package. During testin,
initClient()worked fine when called inside the shared package, but errored on the client.I solved it by downgrading zod to 3.25.10, which seems to be the latest working version. This happened completely at random for me and took some time to debug.