File tree 2 files changed +7
-7
lines changed 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -4021,9 +4021,9 @@ NoInfer 是一种实用类型,旨在阻止泛型函数范围内类型的自动
4021
4021
` ` ` typescript
4022
4022
// 泛型函数范围内类型的自动推断。
4023
4023
function fn<T extends string>(x: T[], y: T) {
4024
- return x.concat(y);
4024
+ return x.concat(y);
4025
4025
}
4026
- const r = fn(["a", "b" ], "c" ); // 此处的类型为 ("a" | "b" | "c")[]
4026
+ const r = fn(['a', 'b' ], 'c' ); // 此处的类型为 ("a" | "b" | "c")[]
4027
4027
` ` `
4028
4028
4029
4029
使用 NoInfer :
Original file line number Diff line number Diff line change @@ -4054,20 +4054,20 @@ Example:
4054
4054
``` typescript
4055
4055
// Automatic inference of types within the scope of a generic function.
4056
4056
function fn<T extends string >(x : T [], y : T ) {
4057
- return x .concat (y );
4057
+ return x .concat (y );
4058
4058
}
4059
- const r = fn ([" a " , " b " ], " c " ); // Type here is ("a" | "b" | "c")[]
4059
+ const r = fn ([' a ' , ' b ' ], ' c ' ); // Type here is ("a" | "b" | "c")[]
4060
4060
```
4061
4061
4062
4062
With NoInfer:
4063
4063
4064
4064
``` typescript
4065
4065
// Example function that uses NoInfer to prevent type inference
4066
4066
function fn2<T extends string >(x : T [], y : NoInfer <T >) {
4067
- return x .concat (y );
4067
+ return x .concat (y );
4068
4068
}
4069
4069
4070
- const r2 = fn2 ([" a " , " b " ], " c " ); // Error: Type Argument of type '"c"' is not assignable to parameter of type '"a" | "b"'.
4070
+ const r2 = fn2 ([' a ' , ' b ' ], ' c ' ); // Error: Type Argument of type '"c"' is not assignable to parameter of type '"a" | "b"'.
4071
4071
```
4072
4072
4073
4073
## Others
@@ -5014,5 +5014,5 @@ with dynamic import:
5014
5014
5015
5015
<!-- skip -->
5016
5016
``` typescript
5017
- const config = import (" ./config.json" , { with: { type: " json" } })
5017
+ const config = import (' ./config.json' , { with: { type: ' json' } });
5018
5018
```
You can’t perform that action at this time.
0 commit comments