Skip to content

Commit ed8d22a

Browse files
committed
🔧 fix: macro should not mark property as required
1 parent 514e2c4 commit ed8d22a

File tree

5 files changed

+89
-33
lines changed

5 files changed

+89
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.4.1 - 14 Sep 2025
2+
Bug fix:
3+
- inline object value / Elysia file cause type error
4+
- macro should not mark property as required
5+
16
# 1.4.0 - 13 Sep 2025
27
Improvement:
38
- support Elysia 1.4

example/a.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { Elysia } from 'elysia'
22
import { treaty } from '../src'
33

4-
const app = new Elysia().get('/test', function* a() {
5-
yield 'a'
6-
yield 'b'
4+
const authMacro = new Elysia().macro({
5+
auth: {
6+
async resolve() {
7+
return { newProperty: 'Macro added property' }
8+
}
9+
}
710
})
811

9-
const client = treaty(app)
12+
const routerWithMacro = new Elysia()
13+
.use(authMacro)
14+
.get('/bug', 'Problem', { auth: true })
1015

11-
const { data } = await client.test.get()
16+
const routerWithoutMacro = new Elysia().get('/noBug', 'No Problem')
1217

13-
for await (const d of data!) {
18+
const app = new Elysia().use(routerWithMacro).use(routerWithoutMacro)
1419

15-
}
20+
const api = treaty<typeof app>('localhost:3000')
1621

17-
console.log(data)
22+
api.noBug.get()
23+
24+
api.bug.get()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/eden",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Fully type-safe Elysia client",
55
"author": {
66
"name": "saltyAom",

src/treaty2/types.ts

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ export namespace Treaty {
5959
[K in keyof Route as K extends `:${string}`
6060
? never
6161
: K]: K extends 'subscribe' // ? Websocket route
62-
? (undefined extends Route['subscribe']['headers']
62+
? ({} extends Route['subscribe']['headers']
6363
? { headers?: Record<string, unknown> }
64-
: {
65-
headers: Route['subscribe']['headers']
66-
}) &
67-
(undefined extends Route['subscribe']['query']
64+
: undefined extends Route['subscribe']['headers']
65+
? { headers?: Record<string, unknown> }
66+
: {
67+
headers: Route['subscribe']['headers']
68+
}) &
69+
({} extends Route['subscribe']['query']
6870
? { query?: Record<string, unknown> }
69-
: {
70-
query: Route['subscribe']['query']
71-
}) extends infer Param
71+
: undefined extends Route['subscribe']['query']
72+
? { query?: Record<string, unknown> }
73+
: {
74+
query: Route['subscribe']['query']
75+
}) extends infer Param
7276
? (options?: Param) => EdenWS<Route['subscribe']>
7377
: never
7478
: Route[K] extends {
@@ -78,14 +82,22 @@ export namespace Treaty {
7882
query: infer Query
7983
response: infer Res extends Record<number, unknown>
8084
}
81-
? (undefined extends Headers
82-
? { headers?: Record<string, unknown> }
83-
: {
84-
headers: Headers
85-
}) &
86-
(undefined extends Query
87-
? { query?: Record<string, unknown> }
88-
: { query: Query }) extends infer Param
85+
? ({} extends Headers
86+
? {
87+
headers?: Record<string, unknown>
88+
}
89+
: undefined extends Headers
90+
? { headers?: Record<string, unknown> }
91+
: {
92+
headers: Headers
93+
}) &
94+
({} extends Query
95+
? {
96+
query?: Record<string, unknown>
97+
}
98+
: undefined extends Query
99+
? { query?: Record<string, unknown> }
100+
: { query: Query }) extends infer Param
89101
? {} extends Param
90102
? undefined extends Body
91103
? K extends 'get' | 'head'
@@ -104,14 +116,23 @@ export namespace Treaty {
104116
ReplaceGeneratorWithAsyncGenerator<Res>
105117
>
106118
>
107-
: (
108-
body: Body,
109-
options?: Prettify<Param & TreatyParam>
110-
) => Promise<
111-
TreatyResponse<
112-
ReplaceGeneratorWithAsyncGenerator<Res>
113-
>
114-
>
119+
: {} extends Body
120+
? (
121+
body?: Body,
122+
options?: Prettify<Param & TreatyParam>
123+
) => Promise<
124+
TreatyResponse<
125+
ReplaceGeneratorWithAsyncGenerator<Res>
126+
>
127+
>
128+
: (
129+
body: Body,
130+
options?: Prettify<Param & TreatyParam>
131+
) => Promise<
132+
TreatyResponse<
133+
ReplaceGeneratorWithAsyncGenerator<Res>
134+
>
135+
>
115136
: K extends 'get' | 'head'
116137
? (
117138
options: Prettify<Param & TreatyParam>

test/types/treaty2.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,3 +1071,26 @@ type ValidationError = {
10711071
unknown
10721072
> | null>()
10731073
}
1074+
1075+
// macro should not mark property as required
1076+
{
1077+
const authMacro = new Elysia().macro({
1078+
auth: {
1079+
async resolve() {
1080+
return { newProperty: 'Macro added property' }
1081+
}
1082+
}
1083+
})
1084+
1085+
const routerWithMacro = new Elysia()
1086+
.use(authMacro)
1087+
.get('/bug', 'Problem', { auth: true })
1088+
1089+
const routerWithoutMacro = new Elysia().get('/noBug', 'No Problem')
1090+
1091+
const app = new Elysia().use(routerWithMacro).use(routerWithoutMacro)
1092+
const api = treaty<typeof app>('localhost:3000')
1093+
1094+
api.noBug.get()
1095+
api.bug.get()
1096+
}

0 commit comments

Comments
 (0)