I use Joi to check the service payload on my node.js server using the hapijs framework. It looked like this (in my typescript code, and also after compiling to javascript):
payload: { para1: Joi.number().required(), para2: Joi.string() }
Now I want to set a default value for two parameters. If the code is written in javascript, I can do this:
payload: { para1: Joi.number().required().default(1), para2: Joi.string().default("defaultstring") }
I tested it in swagger and the default values โโactually became the values โโI set.
However, my project is written in typescript. I did the same and compiled typescript code. The javascript result looks like this:
payload: { para1: Joi.number().required()["default"](1), para2: Joi.string()["default"]("defaultstring") }
In swagger, the default values โโare not applied.
Here are my questions:
- Why does the code become different after compilation?
- what does
["default"]("defaultstring") mean and what does it do? - how can I write typescript code to make sure it can be compiled as
Joi.string().default("defaultstring")
Update
According to @rsp, the format in question 2 is just another way to access the object. I also get a link from here . But that doesnโt explain if they have any difference. Somebody knows?
Update2
There is a difference between the two ways to access the JS property. There seems to be no negative effect using parentheses. However, in my case, the default values โโdo not affect swagger. Will be engaged in research.
source share