面试题答案
一键面试- 使用接口定义类型:
// 定义地址接口 interface Address { province: string; city: string; street: string; } // 定义用户信息接口 interface UserInfo { name: string; age: number; address: Address; } // 函数签名 function getUserInfo(userId: number): UserInfo;
- 使用类型别名定义类型:
// 定义地址类型别名 type Address = { province: string; city: string; street: string; }; // 定义用户信息类型别名 type UserInfo = { name: string; age: number; address: Address; }; // 函数签名 function getUserInfo(userId: number): UserInfo;