Type ‘string | null‘ is not assignable to type ‘string‘. Type ‘null‘ is not assignable to type ‘

报错如下:
Type ‘string | null’ is not assignable to type ‘string’.
Type ‘null’ is not assignable to type ‘string’.ts(2322)
Type ‘string | null‘ is not assignable to type ‘string‘. Type ‘null‘ is not assignable to type ‘_第1张图片

解决办法:

token: localStorage.getItem("token") || ''

你可能感兴趣的:(前端,typescript,前端)