!snippet Typed Interface
export class MyClass {
method(arg: MyInterface):void {}
}
interface User {
name: string;
id: number;
}
const user = {
name: "Bob",
id: 123,
}
use an interface to define type of object
const user: User = {
name: "Bob",
id: 123,
}
export class MyClass implements MyInterface {}
tsxinterface User {name: string;id: number;}
class UserAccount {
name: string;
id: number;
constructor(name: string, id: number) {
this.name = name;
this.id = id;
}
}
use interface to annotate class instance
const user: User = new UseAccount("Bob", 123)