From b376397025c99b596a20b7d318f9ac8eed36e348 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Mon, 23 Sep 2024 11:08:00 +0800 Subject: [PATCH] docs(assert): fixed #119 --- docs/assert.md | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/docs/assert.md b/docs/assert.md index 64aad74..7026698 100644 --- a/docs/assert.md +++ b/docs/assert.md @@ -490,18 +490,9 @@ function assertIsDefined( 上面示例中,工具类型`NonNullable`对应类型`T`去除空类型后的剩余类型。 -如果要将断言函数用于函数表达式,可以采用下面的写法。 +如果要将断言函数用于函数表达式,可以采用下面的写法。根据 TypeScript 的[要求](https://github.com/microsoft/TypeScript/pull/33622),这时函数表达式所赋予的变量,必须有明确的类型声明。 ```typescript -// 写法一 -const assertIsNumber = ( - value:unknown -):asserts value is number => { - if (typeof value !== 'number') - throw Error('Not a number'); -}; - -// 写法二 type AssertIsNumber = (value:unknown) => asserts value is number;