728x90

- Partial Type

Partial<T>

? 로 바꾸기


- Required Type

Required<T>

! 로 바꾸기


- Readonly Type

Readonly<T>

변경 불가능으로 바꾸기


- Pick Type

Pick<T, 'a' | 'b'>

 

뽑아쓰기


- Omit Type

Omit<T, 'a' | 'b'>

빼고쓰기


- Exclude Type

type NoString = Exclude<string | boolean | number, string>; // string 제외된, boolean, number만 가능
type NoFunction = Exclude<string | (() => void), Function>; // Function을 제외해서 string만 가능

특정 타입 제외하기


- Extract Type

type stringOnly = Extract<string | boolean | number, string>; // 선택한 string만 가능
type functionOnly = Extract<string | (() => void), Function>; // 선택한 Function만 가능

특정 타입만 사용하기


-  NotNullable Type

type NonNull = NonNullable<string | number | boolean | null | undefined | object>

null과 undefined를 제거하여 null이 될 수 없게 하기


-  Parameters Type

function sampleFunction(x: number, y: string, z: boolean){}

type Params = Parameters<typeof sampleFunction>

파라미터 가져오기, typeof를 써줘야함


-  ConstructorParameters Type

class Idol {
  constructor(name: string, age: number) {}
}

type ConstructorParamType = ConstructorParameters<typeof Idol>;

constructor의 파라미터 가져오기, typeof를 써줘야함


-  Return Type

type FunctionSign = ()=> number;

type ReturnT = ReturnType<FunctionSign> // number

리턴 타입 가져오기


-  Template Literal Type

type CodeFactory = 'Code Factory';

// Uppercase
type CodeFactoryUpper = Uppercase<CodeFactory>; // "CODE FACTORY"

// Lowercase
type CodeFactoryLower = Lowercase<CodeFactoryUpper>; // "code factory"

// Capitalize
type CodeFactoryCapital = Capitalize<CodeFactoryLower>; // "Code factory" = 첫 글자 대문자

// Uncapitalize
type CodeFactoryUnCapital = Uncapitalize<CodeFactoryCapital>; // "code factory"

https://www.inflearn.com/course/lecture?courseSlug=%EC%BD%94%EB%93%9C%ED%8C%A9%ED%86%A0%EB%A6%AC-%ED%83%80%EC%9E%85%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%ED%92%80%EC%BD%94%EC%8A%A4&unitId=160576&subtitleLanguage=ko&tab=curriculum

 

학습 페이지

 

www.inflearn.com

 

728x90

'코딩 > TypeScript' 카테고리의 다른 글

Generic  (0) 2024.10.31
abstract  (0) 2024.10.30
Overloading  (0) 2024.10.30
const  (0) 2024.10.30
enum  (0) 2024.10.30

+ Recent posts