elysiajs / eden

Fully type-safe Elysia client
MIT License
147 stars 37 forks source link

Treaty 2 unknown status and value types in error #67

Open biohackerellie opened 5 months ago

biohackerellie commented 5 months ago

The Issue

const { data, error } = await client.api.inbox({ chatId: chatId }).get()

// the types show as :
// const data: {
//                id: number
//                message: string
//               }

// const error: {
//              status: unknown
//              value: unknown
                 }

I'm not sure if this is how its supposed to be with treaty 2 but I had proper error types in v1

april83c commented 3 months ago

Same here — I'd expect it to use the return type of my onError function:

.onError(({ code, error }): { code: string } | { code: string, details: ValidationError | string } => { ... })

But even with it explicitly defined here, the error type in the client is just unknown/unknown.

image

It seems viable to have errors be completely type safe, since the status codes are known (custom errors get registered with .error()), and value could just be the return type of onError...? But I guess you have to account for errors that didn't come from Elysia...?