Open bigen1925 opened 9 months ago
I have also ran into this issue! I upgraded from 5.1.1 to this 6.0.0-rc.5 in order to fix this issue with Omit and PIck: https://github.com/lukeautry/tsoa/issues/1238, and now am losing the nullable in the generated swagger
I created a failing unit test for this: https://github.com/gcv-epalmer/tsoa-test
Tried my hand at fixing the bug but I think I'm a bit over my head. My best guess is that the TypeResolver doesn't play super nicely with reference/mapped types
I also encountered this issue while bumping tsoa from 5.1.1 to 6.0.0, I confirm that I lost the nullable
attribute while using Partial
alias in TypeScript:
export default interface UserInsertionBody {
username: string
password: string
roles?: { roleName: ROLE_NAME; siteId: string | null }[]
preferences?: UserPreferences | null
}
I lose nullable
in both roles.siteId
and preferences
attributes when using Partial<UserInsertionBody>
. Thank you @bigen1925 and @gcv-epalmer for pointing it out!
Encountered this as well, attempted to fix it by taking a 4 hour deep dive into this library's internals & typescript AST, and noted the fact that if you enable strictNullChecks
in tsoa's compilerOptions, this stats working again.
Noteworthy however is that with strictNullChecks
enabled, some of tsoa's test suite fails, when I tested just applying that by default in the library itself.
Are there any updates on this? I'd like to get rid of the any
types I am forced to use across the app because the validators won't allow nullables of any type.
Up.
Issue with body validation and Partial as described here: https://github.com/lukeautry/tsoa/issues/1612
Fixed thanks to @iffa with strictNullChecks
@JoranLive, could you explain how is this fixed? I'm having the same issue. I define a property like:
titleTag?: string | null;
But when passing null to it, TSOA throws:
'locations.$0.titleTag': { message: 'invalid string value', value: null }
Thanks!
@vedtam , the workaround is adding "strictNullChecks": true
under compilerOptions
at tsoa config file
@dsambugaro thanks, but compilerOptions aren't taken from tsconfig.json
? I have the flag "strictNullChecks" set there, and been having the issue still.
@vedtam the tsoa.json
also accepts the compilerOptions
. I'm unsure if tsoa takes compilerOptions from tsconfig.json
, or if it has some bug on this behavior since it was only "fixed" when I explicitly set it on tsoa.json
. It is working for me until now
{
"spec": {
...
},
"routes": {
...
},
"compilerOptions": {
"strictNullChecks": true,
}
}
@dsambugaro got it, thanks!
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
Current Behavior
Possible Solution
make nullable information not to be lost
Steps to Reproduce
type ReturnType = Partial<{ nullableString: string | null }>;
@Route("sample") export class SampleController extends Controller { @Get() getSample(): ReturnType { return {} as any; } }