타입스크립트 핸드북
[TIL] 23.03.15 TS 핸드북 - Typeof Type Operator
https://www.typescriptlang.org/ko/docs/handbook/2/typeof-types.html Documentation - Typeof Type Operator 타입 컨텍스트에서 typeof 연산자 사용하기. www.typescriptlang.org typeof 타입 연산자 자바스크립트에 이미 typeof 연산자가 있다. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/typeof typeof - JavaScript | MDN typeof 연산자는 피연산자의 평가 전 자료형을 나타내는 문자열을 반환합니다. developer.mozilla.org 타입스크립트는 타입 컨텍스트에서 변수나 프로퍼티의 타..
[TIL] 23.03.08 TS 핸드북 - More on Functions
https://www.typescriptlang.org/ko/docs/handbook/2/functions.html#%EB%82%98%EB%A8%B8%EC%A7%80-%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98%EC%99%80-%EC%9D%B8%EC%88%98 Documentation - More on Functions TypeScript에서 함수가 어떻게 동작하는지 알아봅시다. www.typescriptlang.org 나머지 매개변수와 인수 나머지 매개변수(Rest Parameter) 정해지지 않은 수의 인수를 받아들이는 함수를 Rest Parameter를 이용해 정의할 수 있다. function multiply(n: number, ...m: number[]) { return m...
[TIL] 23.01.15 타입스크립트 핸드북 - More on Functions(2)
함수 오버로드 몇몇 자바스크립트 함수는 다양한 인수의 개수, 타입을 통해 호출될 수 있다. (eg. Date를 생성하고 인수로 타임스탬프 하나만 받을 수도 있고 월, 일, 연도를 받는 함수를 만들 수도 있다.) 타입스크립트에서는 이를 오버로드 시그니처를 작성함으로써 묘사할 수 있다. 그러기 위해 함수 시그니처 몇 개(보통 2개 이상)를 적은 후 함수 본문을 작성하면 된다. function makeDate(timestamp: number): Date; // 오버로드 시그니처 1 function makeDate(m: number, d: number, y: number): Date; // 오버로드 시그니처 2 function makeDate(mOrTimestamp: number, d?: number, y?: ..
[TIL] 23.01.11 타입스크립트 핸드북 - More on Functions(1)
https://www.typescriptlang.org/ko/docs/handbook/2/functions.html Documentation - More on Functions TypeScript에서 함수가 어떻게 동작하는지 알아봅시다. www.typescriptlang.org 함수 타입 표현식 함수를 설명하는 가장 간단한 방법은 함수 타입 표현식이다. function greeter(fn: (a: string) => void) { fn("Hello, World"); } function printToConsole(s: string) { console.log(s); } greeter(printToConsole); (a: string) => void는 문자열 타입 a를 하나의 매개변수로 가지고 반환값이 없는 ..