面试题答案
一键面试// 定义接口
interface Person {
name: string;
age: number;
}
// 第一个函数
function greet(person: Person) {
console.log(`Hello, ${person.name}! You are ${person.age} years old.`);
}
// 第二个函数
function celebrateBirthday(person: Person) {
person.age++;
console.log(`${person.name} is now ${person.age} years old!`);
}
// 使用函数
const john: Person = { name: 'John', age: 30 };
greet(john);
celebrateBirthday(john);