Skip to content

Optional properties in inferred mapped type causes auto-completion to break.Β #49547

Open
@tippfelher

Description

@tippfelher

Bug Report

Optional properties in inferred mapped type causes auto-completion to break.

πŸ”Ž Search Terms

Inferred mapped type with optional properties no auto-complete

πŸ•— Version & Regression Information

I believe it never worked.

⏯ Playground Link

https://tsplay.dev/mpnLBw

πŸ’» Code

type A1<T extends object> = {
  [K in (keyof T | 'autoCompleteProp')]:
    K extends 'autoCompleteProp'
    ? boolean
    : K extends keyof T
    ? T[K] extends object
    ? A1<T[K]>
    : object
    : never;
}

type A2<T extends object> = {
  [K in (keyof T | 'autoCompleteProp')]?: // <---- this is the only difference compared to A1
    K extends 'autoCompleteProp'
    ? boolean
    : K extends keyof T
    ? T[K] extends object
    ? A2<T[K]>
    : object
    : never;
}

function makeA1<T extends A1<T>>(t: T) {
  return t;
}

function makeA2<T extends A2<T>>(t: T) {
  return t;
}

makeA1({
  autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
  bla: {
    autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
    blubb: {
      autoCompleteProp: false, // <-- you CAN autoComplete 'autoCompleteProp' here
      bleh: {
        // <-- you CAN autoComplete 'autoCompleteProp' here
      }
    },
  },
});

makeA2({
  autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
  bla: {
    // <-- you CAN'T autoComplete 'autoCompleteProp' here
    blubb: {
      // <-- you CAN'T autoComplete 'autoCompleteProp' here
      bleh: {
        // <-- you CAN'T autoComplete 'autoCompleteProp' here
      },
    },
  },
});

πŸ™ Actual behavior

No auto-completion offered by editor or IDE in marked lines when pressing CTRL + SPACE or a

Edit: You can enter autoCompleteProp: '', in the lines where auto-completion fails. The compiler will complain that autoCompleteProp must be a boolean. Thus, the information about the optional property is there, it's just that it never appears in the auto-completion results.

πŸ™‚ Expected behavior

Auto-complete suggestion for "autoCompleteProp" in every line marked with <--

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions