Skip to content

Commit 635a5fa

Browse files
committedOct 12, 2024·
docs(tsconfig.json): fixed #124
1 parent 5361b8c commit 635a5fa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎docs/tsconfig.json.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ let func:StringOrNumberFunc = fn;
679679

680680
### strictNullChecks
681681

682-
不打开`strictNullChecks`的情况下,变量可以设为`undefined``null`,而不管其类型是什么
682+
不打开`strictNullChecks`的情况下,一个变量不管类型是什么,都可以赋值为`undefined``null`
683683

684684
```typescript
685685
// 不打开 strictNullChecks 的情况
@@ -689,9 +689,9 @@ x = undefined; // 不报错
689689
x = null; // 不报错
690690
```
691691

692-
上面示例中,变量`x`的类型是`number`,但是赋值为`undefined``null`都不会报错。这是为了继承 JavaScript 的设定:当变量没有赋值时,它的值就为`undefined`
692+
上面示例中,不打开`strictNullChecks`时,变量`x`的类型是`number`,但是赋值为`undefined``null`都不会报错。这是为了继承 JavaScript 的设定:当变量没有赋值时,它的值就为`undefined`
693693

694-
一旦打开`strictNullChecks`就相当于从变量的值里面,排除了`undefined``null`除非变量的类型是这两种类型
694+
一旦打开`strictNullChecks`就使用严格类型,禁止变量赋值为`undefined``null`除非变量原本就是这两种类型。它相当于从变量的值里面,排除了`undefined``null`
695695

696696
```typescript
697697
// 打开 strictNullChecks 的情况
@@ -701,6 +701,8 @@ x = undefined; // 报错
701701
x = null; // 报错
702702
```
703703

704+
上面示例中,打开`strictNullChecks`时,变量`x`作为`number`类型,就不能赋值为`undefined``null`
705+
704706
下面是一个例子。
705707

706708
```typescript
@@ -709,9 +711,9 @@ x = null; // 报错
709711
type A = unknown extends {} ? string : number;
710712
```
711713

712-
上面示例中,`{}`代表了 Object 类型,不打开`strictNullChecks`时,它包括了`undefined``null`,就相当于包括了所有类型的值,所以这时`unknown`类型可以赋值给`{}`类型,类型`A`就为`number`。打开`strictNullChecks`时,`{}`就排除掉了`undefined``null`,这时`unknown`类型就不能赋值给`{}`类型后,类型`A`就为`string`
714+
上面示例中,`{}`代表了 Object 类型,不打开`strictNullChecks`时,它包括了`undefined``null`,就相当于包括了所有类型的值,所以这时`unknown`类型可以赋值给`{}`类型,类型`A`就为`string`。打开`strictNullChecks`时,`{}`就排除掉了`undefined``null`,这时`unknown`类型就不能赋值给`{}`类型后,类型`A`就为`number`
713715

714-
另外`strict`属性包含了`strictNullChecks`,如果打开`strict`属性,就相当于打开了`strictNullChecks`
716+
最后`strict`属性包含了`strictNullChecks`,如果打开`strict`属性,就相当于打开了`strictNullChecks`
715717

716718
### strictPropertyInitialization
717719

0 commit comments

Comments
 (0)
Please sign in to comment.