Skip to content

[Generic type] Function type of the returned result is not mapped to the parameterΒ #59124

Closed as not planned
@inevermore

Description

@inevermore

πŸ”Ž Search Terms

"Generic Type","Function","Parameters","ReturnType"

πŸ•— Version & Regression Information

  • This is a bug
  • This changed between versions v5.6.0

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKhDOwbmgXigbwFBSgQwC5MdcoBjAewBsKAnIxWgSwDsBzAbhIF8vcAjItlJR+dACYR6URq048uvLFkotE5PFSrwo6YRq1xEQkrhZ4AthCIByMpqpHgNgDSmoAMwCuLMkQA8MFAQAB7AECziOgDWECAUHrAISCgAfAAU0UQwAJS6qcQiuLQQwF60LJjc+DpOyJAA2jAAunyk3G64HVhKWKCQUADCDjp6JA0A0lCsULHxif0QCQbazSYi5lZEE2243r5Ei8v2WvCTzQ02+2Q2rQo9XFiSZFR4JZ4+ZMBMFJUnVABlYDMdhQQLBMIRKKzOLLYanFxQABiEPCkR08O0TQuV0+twyJAAjrQQERMWcWpdNhBbp0oAA6RlvNjwIgABTellKUng-iRqSwOSIACVSuUWPUIHyBcpVOoSvAvFRgLoVkCQWx0nYHE5XFAbHgbDVyL9EDkgA

πŸ’» Code

type TestType = {
  a: {
    color: string;
  };
  b: {
    border: string;
  };
};

const calls = {
  callTest: {
    name: 'callTest',
    func: <T extends keyof TestType>(k: T) => {
      return {} as TestType[T];
    },
  },
};

type Calls = {
  [K in keyof typeof calls]: {
    name: K;
    func: typeof calls[K]['func'];
  };
};

declare const callString = <T extends keyof Calls, F extends Calls[T]['func']>(
  qry: Calls[T]['name'],
  ...args: Parameters<F>
): ReturnType<F>

const result = callString('callTest', 'a' as const)

πŸ™ Actual behavior

result type is {color: string} | {border: string}. The type of the returned result is not mapped to the parameter

  • [ ]

πŸ™‚ Expected behavior

result type is {color: string}. The type should map to parameter 'a'

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions