본문 바로가기

카테고리 없음

[TS] TS Doc Reference 1회독 - 4

ThisParameter<Type>

함수의 this 파라미터 타입을 가져오거나 this 파라미터가 없다면 unknown을 반환합니다.

 

OmitThisParameter<Type>

함수의 this 파라미터 타입의 제거합니다. 만약 this 파라미터가 없다면 단순하게 Type으로 사용됩니다. 해당 타입은 정해진 this 파라미터가 아닌 다른 경우로 함수를 사용하기 위해서 사용됩니다.

 

ThisType<Type>

해당 타입은 문맥적인 this 타입(contextual this type)에 대한 마커입니다. 해당 타입을 사용하기 위해서는 noImplicitThis 플래그를 사용해야 합니다.

 

위 세 가지 타입의 경우 this를 사용하는 경우 사용할 수 있는 것이고 각 역할을 이해했지만, typescript를 접한 지 얼마 지나지 않은 입장에서는 어떻게 활용될 수 있는지 이해하지 못했다.

 

Intrinsic String Manipulation Types

  • Uppercase<StringType>
  • Lowercase<StringType>
  • Capiatalize<StringType>
  • Uncapitalize<StringType>

문자열 타입을 좀 더 세분화시켜서 구분할 수 있도록 도와주는 타입입니다.

let a: Uppercase<string> = 'A';

a = 'a'; // error

let b: Lowercase<string> = 'a';

b = 'B'; // error

let c: Capitalize<string> = 'Apple';

c = 'apple'; // error

let d: Uncapitalize<string> = 'apple';

d = 'Apple'; // error

 

이렇게 유틸리티 타입을 한 번 살펴봤습니다.

 

참고

https://www.typescriptlang.org/docs/handbook/utility-types.html