elysiajs / eden

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

Type Issue with params Property in Eden Fetch #40

Closed trylovetom closed 8 months ago

trylovetom commented 8 months ago

First off, I want to express my appreciation for the Elysia project! It's been instrumental in building efficient and type-safe servers, and the thoughtfulness in design truly shows. I've been using it for a while and am continually impressed by its capabilities and performance.

Expected

I was expecting to utilize the edenFetch from @elysiajs/eden with App type from server.ts without encountering type errors, ensuring smooth integration between client and server-side code.

Actual

However, I encountered a TypeScript error when trying to use the edenFetch with the App type. The error is as follows:

Property 'params' is missing in type '{}' but required in type '{ params: never; }'.ts(2345)
types.ts(40, 23): 'params' is declared here.
Screenshot 2024-01-02 at 10 10 25 AM

Reproduction

The following code represents a simplified scenario based on the official example provided in the Elysia documentation for edenFetch. I've encountered the TypeScript error while working with this example directly from the Elysia Eden Fetch Documentation.

// server.ts
import { Elysia, t } from 'elysia'

const app = new Elysia().get('/', () => 'Hi Elysia').listen(8080)

export type App = typeof app
import { edenFetch } from '@elysiajs/eden'
import type { App } from './server'

const fetch = edenFetch<App>('http://localhost:8080')

// response type: 'Hi Elysia'
const pong = await fetch('/', {})

I understand the challenge and intricacies involved in type definitions and intersection types, especially when dealing with external type declarations. I suspect this issue might be related to the intersection types or perhaps an optional property that isn't set correctly in the typings.

I'm not entirely sure of the best solution here, but I wanted to bring it to your attention in case it's something that can be improved or if there's a workaround that I'm not aware of. Your insight and guidance would be immensely valuable.

Thank you again for all your hard work on this project. It's been a pleasure to use, and I look forward to continuing with it!

fredericoo commented 8 months ago

Super easy fix, not as complex as you thought 🤣

trylovetom commented 8 months ago

@fredericoo Wonderful you are great! I am not good at typescript.