Skip to content

Code completion stopped working for a few scenarios in typescript 5.1 #54710

Closed
@pedrodurek

Description

@pedrodurek

Bug Report

Scenario 1: Code completion stopped working by adding an undefined as the default value for the generic type. TypeScript narrows down the range of expected argument types, and as a result, the code completion doesn't work correctly. It works fine in Typescript 5.0 or below.

Scenario 2: Code completion stopped when using an overloaded function type that combines union types with named tuples containing a generic type parameter. it works fine in Typescript 5.0 or below.

🔎 Search Terms

Code completion issues in typescript 5.1

🕗 Version & Regression Information

The Issue started occurring on typescript 5.1 and beyond. It works fine in versions 5.0 or below.

⏯ Playground Link

Scenario 1: https://tsplay.dev/w1xZGW
Scenario 2: https://tsplay.dev/WKvGZm

💻 Code

Scenario 1:

declare function func<
  const T extends 'a' | 'b' | undefined = undefined,
>(arg?: T): string;

// Code completion does not work
func('')

Scenario 2:

interface Func {
  <Key extends 'a' | 'b'>(
    ...args:
      | [key: Key, options?: any]
      | [key: Key, defaultValue: string, options?: any]
  ): string;
}

declare const func: Func;

// Code completion does not work
func('');

🙁 Actual behavior

Code completion doesn't work

🙂 Expected behavior

Code completion should work as in the images below:

Screenshot 2023-06-19 at 2 20 43 PM Screenshot 2023-06-19 at 2 21 31 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions