Skip to content

Implicitly typed parameters of function properties of generic parameters break autocompletion #46916

Open
@yusufkandemir

Description

@yusufkandemir

Bug Report

🔎 Search Terms

generic parameter autocomplete
extends autocomplete
parameter breaks autocomplete
implicit parameter breaks autocomplete

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about (almost?) everything
  • I was unable to test this on prior versions because TS v3.3.3 acts function parameters as implicitly any, while 3.5.1 and higher versions(the ones on the playground) correctly get the type as a string.

⏯ Playground Link

Playground link with relevant code

💻 Code

// (Simplified)
interface StepDefinition {
  title: string;
  enabled: true | ((foo: string) => boolean);
}

// To avoid TS from narrowing the keys to 'string' and definitions to just StepDefinition
function defineSteps<T extends Record<keyof T, StepDefinition>>(steps: T) {
  return steps;
}

const STEPS = defineSteps({
  test: {
    title: 'Test',
    enabled: true,
  },
  bar: {
    title: 'Foo Bar',
    enabled: (foo: string) => foo.length > 0, // When this is enabled, baz: { ... } gets auto-completion
    // enabled: () => 'foo'.length > 0, // When this is enabled, baz: { ... } gets auto-completion
    // enabled: (str) => str.length > 0 // When this is enabled, baz: { ... } does NOT get auto-completion
  },
  //baz: {
    
    // enabled: () => [].concat([ 1 ]).length > 0, // When this is enabled, auto-completion here still works
    // enabled: (foo) => !!foo, // When this is enabled, auto-completion here stops working
  //}
});

// The code below is for context
export type Steps = typeof STEPS;

// The aim is getting the step names and other types while also having IntelliSense when defining the steps
export type StepNames = keyof Steps;
export type ConditionalSteps = {
  [S in keyof Steps]: Steps[S]['enabled'] extends true ? never : S;
}[keyof Steps];

// ...

🙁 Actual behavior

No autocomplete inside defineSteps({ ... }) after defining a function with an implicitly typed parameter in any of enabled properties. TS can't even get the parameter type implicitly on v3.3.3, so my guess is some stuff got improved which helped to infer the type, but there is something slightly wrong under the carpet, which causes this.

🙂 Expected behavior

Getting autocomplete inside defineSteps({ ... }), even when I define a function with an implicitly typed parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editor

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions