Argument type 'string | null' not assignable to parameter type 'string | number | boolean'

Issue

Argument of type ‘string | null’ is not assignable to parameter of type ‘string | number | boolean’.
Type ‘null’ is not assignable to type ‘string | number | boolean’.ts(2345)
(property) User.token: string | nullenter image description hereenter code here

enter image description here

Solution

you can explicitly tell ts that this string is not null by the ! bang operator, if you are really sure it will be there

.set('auth', user.token!)

Answered By – Andrei

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published