화살표 함수의 () => x 표현은 () => { return x; }의 약식 표현이므로 잘 작동합니다.
(...매개변수 나열) => 반환 타입
매개변수가 없는 함수의 경우 매개변수를 생략
() => 반환 타입
예
const yetAnotherSum: (a: number, b: number) => number = sum;
const onePlusOne: () => number = () => 2;
const arrowSum: (a: number, b: number) => number = (a, b) => (a + b);
함수 시그니처 부분(매개변수부터 리턴타입지정된 부분까지)을 별칭 지정할 수 있다.
type SumFunction = (a: number, b: number) => number;
const definitelySum: SumFunction = (a, b) => (a + b);
함수 시그니처 예제2
const sayHello: (name: string, age: number) => void = function(name: string, age: number): void {}
type sayHello = (name: string, age: number) => void
const hello: sayHello = (a, b) => {
console.log(`이름: ${a}, 나이: ${b}`)
}
// 함수 시그니처를 사용하지 않은 동일 함수
function basicHello(name: string, age: number): void {
console.log(`이름: ${name}, 나이: ${age}`)
}
https://ahnheejong.gitbook.io/ts-for-jsdev/03-basic-grammar/function
https://velog.io/@solchan/Typescript-%ED%95%A8%EC%88%98%EC%99%80-%EB%A9%94%EC%84%9C%EB%93%9C
'┝ 개발 언어 > ┝ html_css_js' 카테고리의 다른 글
script 태그 안의 async란 (0) | 2023.07.07 |
---|---|
js await와 async (0) | 2023.06.29 |
[js] location.href 시에 url이 중복되는 현상 (0) | 2022.07.06 |
ㄱ html 목차 (0) | 2022.03.01 |
2020/06/25(8) 미니프로젝트-2(메인페이지 작성2) (0) | 2022.03.01 |