Function Type Expressions

function hi(fn: (sentence: string) => void) {
    fn('안녕!');
}

function sayHi(message:string) {
    console.log(message);
}

hi(sayHi);

→ 이런식으로 표현 될때 parameter는 required 된다.

물론 이름을 붙여서 type alias 방식으로도 사용될 수 있다.

type SayHiFunction = (message: string) => void
function greeter(fn: SayHiFunction){
}

Call Signatures

Construct Signatures

type SomeConstructor = {
	new (s:string) : SomeObj;
}
function fn( ctor: SomeConstructor){
	return new ctor('HI!!!!')
}

어떤 객체는 — 자바스크립트 date 객체처럼— new 없이도 호출 될 수 있다. 이런 경우에는 호출(call)과 생성자(construct) 방식을 선택하여 사용하면 된다.

Generic Functions