-
-
Notifications
You must be signed in to change notification settings - Fork 474
/
path-params.test-d.ts
55 lines (44 loc) · 1.15 KB
/
path-params.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { rest } from 'msw'
rest.get<never, { userId: string }>('/user/:userId', (req) => {
req.params.userId
// @ts-expect-error `unknown` is not defined in the request params type.
req.params.unknown
})
rest.get<never>('/user/:id', (req, res, ctx) => {
const { userId } = req.params
return res(
ctx.body(
// @ts-expect-error "userId" parameter is not annotated
// and is ambiguous (string | string[]).
userId,
),
)
})
rest.get<
never,
// @ts-expect-error Path parameters are always strings.
// Parse them to numbers in the resolver if necessary.
{ id: number }
>('/posts/:id', () => null)
/**
* Using interface as path parameters type.
*/
interface UserParamsInterface {
userId: string
}
rest.get<never, UserParamsInterface>('/user/:userId', (req) => {
req.params.userId.toUpperCase()
// @ts-expect-error Unknown path parameter "foo".
req.params.foo
})
/**
* Using type as path parameters type.
*/
type UserParamsType = {
userId: string
}
rest.get<never, UserParamsType>('/user/:userId', (req) => {
req.params.userId.toUpperCase()
// @ts-expect-error Unknown path parameter "foo".
req.params.foo
})