22 lines
363 B
TypeScript
22 lines
363 B
TypeScript
let id: number | string = 1;
|
|
|
|
interface User {
|
|
name: string;
|
|
age?: number;
|
|
}
|
|
id = "hello"
|
|
const userA: User = {
|
|
name: "小李",
|
|
age: 18
|
|
}
|
|
const userB: User = {
|
|
name: "小柔"
|
|
}
|
|
console.log(userA, userB);
|
|
|
|
// 任务:
|
|
// 1. 把 id 改成字符串也试一次
|
|
// 2. 创建一个带 age 的 userA
|
|
// 3. 创建一个不带 age 的 userB
|
|
// 4. 输出它们
|