Typescript 주의 사항 4: `${infer P}`를 확장하지 않으면 `${infer P}/`를 확장하지 않는 것과 다른 결과가 나타납니다.

type a = never extends `${infer P}` ? P : 1  // never
//   ^?
type b = never extends `${infer P}/` ? P : 2 // string
//   ^?

type a1 = never extends `${infer P extends string}` ? P : 1 // never
//   ^?
type b1 = never extends `${infer P extends string}/` ? P : 2 // string
//   ^?

type a2 = never extends `${infer P extends number}` ? P : 1 // never
//   ^?
type b2 = never extends `${infer P extends number}/` ? P : 2 // number
//   ^?

type a3 = never extends `${infer P extends null}` ? P : 1 // never
//   ^?
type b3 = never extends `${infer P extends null}/` ? P : 2 // null
//   ^?

type a4 = never extends `${infer P extends undefined}` ? P : 1 // never
//   ^?
type b4 = never extends `${infer P extends undefined}/` ? P : 2 // undefined
//   ^?

type a5 = never extends `${infer P extends boolean}` ? P : 1 // never
//   ^?
type b5 = never extends `${infer P extends boolean}/` ? P : 2 // boolean
//   ^?

type a6 = never extends `${infer P extends bigint}` ? P : 1 // never
//   ^?
type b6 = never extends `${infer P extends bigint}/` ? P : 2 // bigint
//   ^?


playground

이것은 bug

좋은 웹페이지 즐겨찾기