Front-end/타입스크립트로 블록체인 만들기

[TS] Call Signatures

탱 'ㅅ' 2023. 12. 15. 10:45

함수의 parameter type과 return type을 미리 지정하는 것

the type of the arguments and return value of a function 🙆🏻‍♀️

the implementaion(이행, 실행) of a function ❌ 

 

그 함수를 구현하기 전에

먼저 함수의 타입을 설명하고,

함수가 어떻게 작동하는지 서술해둘 수 있다. 

 

 

before

// normal function
function add(a: number, b: number) {
	return a+b
}
// arrow function
const add = (a: number, b: number) => a+b

 

after

type Add = (a: number, b: number) => number


const add:Add = function(a, b) {
	return a+b
}
const add:Add = (a, b) => a+b
const add:Add = (a, b) => { a+b } // ❌ ∵return값 없는 void 형태!!

 

- 함수 위에 마우스를 올렸을 때 보게 되는 것

 

- React에서 props로 함수를 전달할 때, 어떻게 작동할지 미리 설계 가능!

 

- type 다르면 반환하지 않는다.

 

- JS로 컴파일되지 않는다.

 

 

 

 

Documentation - More on Functions

Learn about how Functions work in TypeScript.

www.typescriptlang.org

 

 

Signature (functions) - MDN Web Docs 용어 사전: 웹 용어 정의 | MDN

함수 시그니처(타입 시그니처, 메소드 시그니처)는 functions 그리고 methods의 입력과 출력을 정의합니다.

developer.mozilla.org

 

'Front-end > 타입스크립트로 블록체인 만들기' 카테고리의 다른 글

[TS] HW - Polymorphism, Generic Type  (1) 2023.12.21
[TS] Polymorphism 다형성  (0) 2023.12.20
[TS] Why not JavaScript  (0) 2023.12.18
[TS] Overloading  (0) 2023.12.15
[TS] Types of TS  (0) 2023.10.10