티스토리 뷰

웹 개발/Typescript

function in interface

투자유v 2022. 1. 4. 01:01
728x90
interface Person {
  name: string;
  age?: number;
  hello(): void;
}

const p1: Person = {
  name: "hyun",
  hello: function (): void {
    console.log(`Hi, my name is ${this.name}`);
  },
};

const p2: Person = {
  name: "kim",
  hello(): void {
    console.log(`Hi, my name is ${this.name}`);
  },
};

'웹 개발 > Typescript' 카테고리의 다른 글

type vs. interface  (0) 2022.01.04
interface 기본  (0) 2022.01.04
optional property in interface  (0) 2022.01.04
never와 void  (0) 2022.01.01
unknown과 타입 가드: any의 불안정함을 대체하기 위해  (0) 2021.12.30
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함