Skip to content

Wrong code suggestion when using "Mapped Types" as function parameter #55545

Closed
@lNaymonl

Description

@lNaymonl

Type: Bug

Extension version: 5.3.20230827

Version: 1.81.1 (user setup)
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:22:42.175Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045

Problem:
The Codesuggestion shows "1", "2", "3", "4" event though a is "valA". When hovering it also shows that b has type "1" | "2". And when i select "3" or "4" it gives me the following error:
Argument of type '"3"' is not assignable to parameter of type '"1" | "2"'.

Screenshot (7)

Expected:
The Codesuggestion should only display"1" and "2".

Source Code:

enum myEnum {
  valA = "valA",
  valB = "valB",
}

interface myEnumParamMapping {
  ["valA"]: "1" | "2";
  ["valB"]: "3" | "4";
}

function myFunction<K extends keyof typeof myEnum>(a: K, b: myEnumParamMapping[K]) {
  console.log({ a, b });
}

myFunction("valA", "2");

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions