# 05 · assertion-functions **演示**:`asserts value is string` 让调用之后的代码直接按 `string` 使用;失败路径抛 `TypeError`。 **运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开 `http://localhost:8080/examples/03-literal-types-narrowing/05-assertion-functions/`;开 Console。 **预期控制台输出**: ```text ts threw:TypeError ok ``` **类型检查**:`node node_modules/typescript/bin/tsc -p examples/03-literal-types-narrowing/05-assertion-functions/tsconfig.types.json` **注意**:断言函数必须用函数声明或显式类型的函数表达式;箭头函数不能带 `asserts` 返回标注。