Closed
Description
// 写法一
const assertIsNumber = (value: unknown): asserts value is number => {
if (typeof value !== 'number')
throw Error('Not a number');
};
assertIsNumber(1)
tsconfig.json
("typescript": "^5.6.2")
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"exactOptionalPropertyTypes": true,
"module": "NodeNext",
"moduleResolution": "nodenext",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "ESNext",
"useUnknownInCatchVariables": false
}
}
Metadata
Metadata
Assignees
Labels
No labels