Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boolean | null auto translates to false ? #1720

Closed
JimmyBjorklund opened this issue Nov 18, 2024 · 3 comments
Closed

boolean | null auto translates to false ? #1720

JimmyBjorklund opened this issue Nov 18, 2024 · 3 comments

Comments

@JimmyBjorklund
Copy link

Hi
Have an update request that looks like this

interface UpdateRequest {
  u: boolean | null
}

@Put("g/{id}")
async updateU(id: string, @Body() body: UpdateRequest ): Promise<void> {
   console.log("update", body);
}

When trying to pass null to the variable u it auto translates to false instead of null that one would expect.
Is this expected?
/Jimmy

@JimmyBjorklund
Copy link
Author

Found another strang thing if i set
u: "null" | boolean;
Then passing both null and "null" seems to work, this seams wrong if i set a string "null" then null should not work ?

@ajball
Copy link

ajball commented Dec 3, 2024

Ran into the same bug. My workaround:

// tsoa.json
{
  ...
  "routes": {
     ...
    "bodyCoercion": false
  }
}

@JimmyBjorklund
Copy link
Author

JimmyBjorklund commented Dec 3, 2024

bodyCoercion

Thanks for the tip!.

@WoH WoH closed this as completed Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants