• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

브랜딩 기법 질문드립니다.

23.01.16 17:11 작성 조회수 189

0

type Awaited<T> =
    T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
        T extends object & { then(onfulfilled: infer F, ...args: infer _): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
            F extends ((value: infer V, ...args: infer _) => any) ? // if the argument to `then` is callable, extracts the first argument
                Awaited<V> : // recursively unwrap the value
                never : // the argument to `then` was not callable
        T; // non-object or non-thenable

여기서 object & { then }도 브랜딩 기법을 사용한 건가요? duck typing과 브랜딩의 차이점이 궁금합니다.

답변 1

답변을 작성해보세요.

1

브랜딩이자 duck typing입니다. then이 있으면 프로미스 객체라고 보는 것이니까 덕타이핑이고, then 자체가 객체에 차별성을 부여하는 것이므로 브랜딩입니다.

브랜딩은 객체가 다른 객체와 구별되느냐에 중점을 둔 기법이고, 덕타이핑은 객체가 다른 객체에 속하느냐를 보는 방법입니다.