From 1ec3a43ab625936d027b025e6372e6422b1dffbb Mon Sep 17 00:00:00 2001 From: "WRSNDM\\Administrator" Date: Sun, 4 Jan 2026 23:26:58 +0800 Subject: [PATCH] no message --- ts/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ts/README.md b/ts/README.md index fd4dae5..a722c3a 100644 --- a/ts/README.md +++ b/ts/README.md @@ -13,6 +13,22 @@ ## 1. 基础概念与类型系统 +在深入面试题之前,我们先快速梳理一下 TypeScript 的类型系统版图: + +- 基础类型 (Primitives):`string`, `number`, `boolean`, `null`, `undefined`, `symbol`, `bigint` +- 顶层类型 (Top Types): + - `any`:关闭类型检查,尽量避免 + - `unknown`:类型安全的 any,使用前需类型收窄 +- 底层类型 (Bottom Type): + - `never`:不可能出现的值(如抛错/死循环的返回) +- 复合类型 (Composed Types): + - 联合类型 (Union Types):`string | number`(是 A 或 B) + - 交叉类型 (Intersection Types):`TypeA & TypeB`(同时满足 A 与 B) + - 元组 (Tuple):定长定类型数组,如 `[string, number]` +- 对象类型:`interface`、`type`(对象字面量、映射类型)、`class`、字面量类型 `{ name: string }` + +--- + ### Q1: `interface` 和 `type` (Type Alias) 的核心区别是什么?在什么场景下应该优先使用哪一个? **解析:**