有没有办法关掉
Type 'string' is not assignable to type 'null'.ts(2322)
Run Code Online (Sandbox Code Playgroud)
我编写的代码使用了空类型检查,因为它不能是空字符串检查。如果我按照打字稿的要求并将字符串设置为未定义或空,则会在各处产生很多其他错误,例如
Variable 'value2' is used before being assigned.ts(2454
Run Code Online (Sandbox Code Playgroud)
是否有一个标志可以关闭此功能?
示例代码:
function check(value: string, value2: string = null) { // error here
if (value2==null) {
//
}
}
Run Code Online (Sandbox Code Playgroud)
示例2:
var value: string = null; // error here
Run Code Online (Sandbox Code Playgroud)
另外,我想关闭这个:
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.ts(2345)
Run Code Online (Sandbox Code Playgroud)
有打字稿编译选项吗?
根据您的代码,实际类型是string | null.
示例1:
function check(value: string, value2: string | null = null) {
if (value2==null) {
//
}
}
Run Code Online (Sandbox Code Playgroud)
示例2:
var value: string | null = null;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
299 次 |
| 最近记录: |