TypeScript-面试-基础类型与类型注解
2026年10月16日·Admin·1 次浏览
面试题:TS 常见基础类型?null / undefined 在类型里怎么用?
基础类型
number、string、boolean、bigint、symbol、object(注意 object 非 {} 一切)。
特殊
null/undefined:可单独成类型;严格空值检查strictNullChecks打开后,string不含 null/undefined,需写string | null。void:函数无返回值或返回undefined(console.log类)。never:不可达或必抛错的函数的返回类型,也是空联合的底类型。
数组与元组
number[]/Array<number>。- 元组
[string, number]:固定长度与位置类型;可选元素、rest 可扩展。
对象类型
{ name: string; age?: number },可选属性 ?,只读 readonly。