# 02 · discriminated-union **演示**:`kind` 字段把联合变成可辨识联合,`switch` 逐分支收窄,`never` 兜底。 **运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开 `http://localhost:8080/examples/08-unions-intersections/02-discriminated-union/`;开 Console。 **预期控制台输出**: ```text 3.14 9 10 ``` **类型检查**:`node node_modules/typescript/bin/tsc -p examples/08-unions-intersections/02-discriminated-union/tsconfig.types.json` **预期类型错误**(`demo/no-narrowing.ts`,由 `tsconfig.fail.json` 触发): ```text demo/no-narrowing.ts(8,16): error TS2339: Property 'radius' does not exist on type 'Shape'. ``` **注意**:`kind` 必须是字面量类型;写成 `string` 就无法收窄。