ts-rest / ts-rest

RPC-like client, contract, and server implementation for a pure REST API
https://ts-rest.com
MIT License
2.11k stars 91 forks source link

Boolean query parameter always true #589

Closed GraceG7 closed 2 months ago

GraceG7 commented 2 months ago

Describe the bug

I've recently upgraded from version version 3.30.1 to 3.41.2 and I've noticed a potential bug with the boolean query parameter

Here's my the query parameter defined in the contract

method: 'GET ',
path: "get-something",     
query: z.object({
        show: z.coerce.boolean(),
}),
responses: {
     200: c.type<any>()
}

In my ts rest handler that is implementing this endpoint, r.query.show is always true despite passing false to it.

I've inspected the network request and it shows that the value false is sent to the api on the show query param so I'm very confident that there isn't an error on where it is called.

Thanks in advance for the help

How to reproduce

Expected behavior

No response

Code reproduction

// Add your code reproduction here

ts-rest version

3.41.2

robert-king commented 2 months ago

I think this is because Boolean('false') is truthy, if so, can probably close this as working as expected

GraceG7 commented 2 months ago

Curious to know why it used to work in previous version in this case

Gabrola commented 2 months ago

You can only use string types for query parameters unless you enable jsonQuery