본문 바로가기

Web/Typescript

Interface

Interface = object 에 대한 타입

여러 개의 함수와 여러 개의 변수 등이

구조적으로 어떻게 결합되어야 하는지에 대한 약속

하나의 함수가 가져야 할 구조에 대한 약속

interface Person {
    name: string;
    age?: number; // optional

    move(): void;
}

var person: Person= {
    name: "John",
    move: () => { }
};

var person2: Person = {
    name: "John",
    age: 42,
    move: () => { }
}

var person3: Person = {
    name: "John:,
    age: true
}
// Interfaces can also describe a function type
interface SearchFunc {
    (source: string, substring: string): boolean;
}

// Only the parameters' types are important, names are not important.
var mySearch: SearchFunc;
mySearch = function (src: string, sub: string) {
    return src.search(sub) 
}


'Web > Typescript' 카테고리의 다른 글

callback, popup  (0) 2017.03.22
class  (0) 2017.03.22
오브젝트 (Object)  (0) 2017.03.22
반복문 (Loops)  (0) 2017.03.21
조건문 (conditions)  (0) 2017.03.21