We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dd06fc5 commit b376397Copy full SHA for b376397
docs/assert.md
@@ -490,18 +490,9 @@ function assertIsDefined<T>(
490
491
上面示例中,工具类型`NonNullable<T>`对应类型`T`去除空类型后的剩余类型。
492
493
-如果要将断言函数用于函数表达式,可以采用下面的写法。
+如果要将断言函数用于函数表达式,可以采用下面的写法。根据 TypeScript 的[要求](https://github.com/microsoft/TypeScript/pull/33622),这时函数表达式所赋予的变量,必须有明确的类型声明。
494
495
```typescript
496
-// 写法一
497
-const assertIsNumber = (
498
- value:unknown
499
-):asserts value is number => {
500
- if (typeof value !== 'number')
501
- throw Error('Not a number');
502
-};
503
-
504
-// 写法二
505
type AssertIsNumber =
506
(value:unknown) => asserts value is number;
507
0 commit comments