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

753 阅读1分钟

第一种情况

报错如下:

Type ‘string | nullis not assignable to type ‘string’.
Type ‘nullis not assignable to type ‘string’.ts(2322)

解决办法:

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

第二种情况

报错如下:

image.png

解决办法:

image.png