typeParamater 의 타입을 유추하는것

용어

context

// in chooseOverload 
...
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
...

candidate.typeParameters로 inferenceContext 를 만듬

기본동작

context-senstive

미리 타입을 선언했을시

conditional type

결론

api의 타입을 설계할때

  1. typeParamter 는 object 로 안하는게 좋음
    1. callback(context-sensitive) 예제에서 문제 생길 가능성이 높음
    2. 좀더 쉽게 추론하려는 이슈도 있음 https://github.com/microsoft/TypeScript/issues/53999
  2. 타입을 추론할때는 Infer 키워드를 안쓰는게 나음
    1. 타입을 미리 추론하고 Infer 키워드를 써야함
  3. arg 를 배열로 받으면 callback 까지는 제대로 infer 안될 수 있음