ecyrbe/zodios

How to split into different files and keep type safety?

Closed this issue · 3 comments

Error: Property 'getFiles' does not exist on type 'ZodiosInstance<any[]>'.ts(2339)

Example

api.ts

import {  makeApi } from '@zodios/core'
import files from './files'

export const api = mergeApis({
  '/files': files
})

files.ts

// ...
export default apiBuilder({
  method: 'get',
  path: '/',
  alias: 'getFiles',
  description: 'Get all files',
  response: FilesSchema,
  errors: FilesErrors,
}).build()

test.ts

import { api as apiDefinition } from './api'
// ...
const api = new Zodios(url, apiDefinition)
const response = await api.getFiles()
//                         ^^^^^^^^ Property 'getFiles' does not exist on type 'ZodiosInstance<any[]>'.ts(2339)

The request works, only the type error occurs.

When I put files.ts content into api.ts everything is ok.

@zodios/core: 10.9.6
zod: 3.22.4
typescript: 5.3.3

tsconfig.json

{
  "compilerOptions": {
    "composite": true,                                  
    "target": "ESNext",                                 
    "experimentalDecorators": true,                     
    "module": "ESNext",                                 
    "moduleResolution": "node",                         
    "noEmit": true,                                     
    "isolatedModules": true,                            
    "allowSyntheticDefaultImports": true,               
    "esModuleInterop": true,                            
    "verbatimModuleSyntax": true,                       
    "strict": true,                                     
    "skipLibCheck": true                               ,
  }
}

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.

@Farnsi check your other typescript errors. I'm not sure if this is you're problem, but it seems like you should be importing mergeApis in api.ts.

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.