class People {name: string;age: number;constructor(name: string, age: number) {this.name = name;this.age = age;}eat(food: string): void {console.log("eat", food);}}const p = new People("zhangsan", 18);p.eat("apple");
定义了一个类,还会自动定义一个接口。
interface People {name: string;age: number;eat: (food: string) => void;}
