0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【TypeScript】Conditional Types

Posted at

conditional types

// type Exclude<T, U> = T extends U ? never : T;
type MyExclude = 
( string extends string | number ? never : string )  // never
| ( number extends string | number ? never : number )  // never
| ( DebugType extends string | number ? never : DebugType )  // DebugType
type MyFunctionType = MyExclude

infer

type MyReturnType<T extends (...args: any) => any> = T extends (
  ...args: any
) => infer R 
? R 
: any;
// infer = 条件の一部としてジェネリクス型(<T extends (...args: any) => any>)を宣言することができる
// infer R = <T extends (...args: any) => any> 後ろのanyを取得
// (...args: any) => any = 関数を意味する → Tは関数
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?