Skip to content

Intellisense for generic parameterized string literal function arguments not working #26662

Open

Description

@mjbvz

From Nate Graf (@njgraf512) on July 31, 2018 22:5

  • VSCode Version: 1.26.0-insider
  • OS Version: MacOS 10.12.6

Steps to Reproduce:

  1. Enter the following into a TS file:
const myObj =  {
  foo: 'Foo',
  bar: 'Bar',
}

function myFunc<T>(obj: T, key: keyof T) {
  return obj[key];
}

myFunc(myObj, 'f')
  1. Observe that once you begin typing the f of string literal foo for the function's second argument, the tooltip switches from suggesting "foo" | "bar" to never:

Good:

screen shot 2018-07-31 at 2 52 01 pm

Bad:

screen shot 2018-07-31 at 2 52 48 pm

  1. Also, triggering intellisense with control+space does not suggest foo or bar:

screen shot 2018-07-31 at 2 52 26 pm

Does this issue occur when all extensions are disabled?: Yes/No
No

Copied from original issue: microsoft/vscode#55530

Activity

  1. mjbvz commented on Aug 24, 2018

    @mjbvz
    ContributorAuthor

    Tested with typescript@3.1.0-dev.20180824 IntelliSense issue still sees to exist

  2. RyanCavanaugh commented on Aug 24, 2018

    @RyanCavanaugh
    Member

    The issue here is that mid-call, T really is {} and it really is "correct" to not suggest "Foo"/"Bar" because there are no members of {} with that name. We need to somehow "back out" the inference to typeof myObj and then get its keys instead; probably a nontrivial fix.

  3. njgraf512 commented on Aug 24, 2018

    @njgraf512

    Ryan Cavanaugh (@RyanCavanaugh), just to confirm, when you say mid-call, you're referring to once a string '' (quote) token is added for the start of the second argument? I ask because you'll notice in the screenshot from number 3 above, intellisense is correctly suggesting "foo" | "bar". Note that I think that even just adding these two string suggestions that are currently shown in the tooltip to the popout autocomplete list would be a nice improvement.

  4. mkantor commented on Feb 10, 2026

    @mkantor
    Contributor

    I think this has been addressed. I'm unable to reproduce the described behavior in the playground using any version of TypeScript available there (the oldest is 3.3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: LS: Completion ListsThe issue relates to showing completion lists in an editorExperience EnhancementNoncontroversial enhancementsSuggestionAn idea for TypeScriptVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions