代码没有问题,为什么typescript编译失败?
通过命令 npx tsdx create packages 生成 typescript + react 项目,某个文件的代码编译不通过:
let test: string | undefined = undefined
test ??= '555' // 编译不能通过
if (typeof test === 'undefined') test = '555' // 换成这样可以通过编译
错误内容如下:
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
✓ Creating entry file 1.5 secs
(typescript) Error: syntax error TS1109: Expression expected.
请问这是为什么呢?难道 typescript 不支持 js 的 ??= 运算吗?
??= 不是检测是不是null嘛