前言 TypeScript 的官方文档早已更新,但我能找到的中文文档都还停留在比较老的版本。所以对其中新增及修改较多的一些章节进行了个人的翻译整理。 本篇整理自 https://www.typescriptlang.org/docs/handbook/2/narrowing.html 本文并不完全遵循原文翻译,对部分内容自己也做了解释补充。 Narrowing 试想我们有这样一个函数,函数名为 padLeft: function padLeft(padding: number | string, input: string): string { throw new Error("Not i...