Microsoft/TypeScript

Inferred Promise type breaks ordering of completions

开放

#56,978 创建于 2024年1月8日

 (0 条评论) (0 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
Domain: LS: Completion ListsExperience EnhancementHelp WantedSuggestion

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

🔎 Search Terms

promise, generic, completion, inference

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about promise/completions (found nothing)

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt0B4AqA+ZCAD0hABMBnZABSnQFtgKJcCBvAKGWQHofkcACybIKg9AFcANmVHiA7sgkAHZDGBQKYZHCnoQAc2TzgYQcgRwwCQQBpkZiCHvqQuqQE97EawDouapgAFACUAFzIINJSANwcAL4cHFI+yAaYZBEY2ADaALp4cRx8yACSIMgAagDKyADC6GQQ9mBQHg4eyqAGYcU8fdxpGf5JMBIgCGDA+sgARnBkrEFEETjhaJisyJzcUD4SUBVRUlI6VHAgHnGJSSXlVbUNTS1tHV2GvXwD3PNkQfkhXxAA

💻 Code

interface Foo<T> extends Promise<T> {
  // This should show up first along with catch, then, finally, etc.
  foo(): null;
}

let good: Foo<[]>;

async () => {
  // In VS Code, try typing:
  //
  //   good.
}

function bad<T>(x: T): Foo<T> {
  return null as any;
}


async () => {
  // In VS Code, try typing:
  //
  //   bad([]).
}

🙁 Actual behavior

If a generic is used to infer the type contained in the Promise, then the completions ordering is lost.

This is the correct ordering, foo shows up towards the top: Screenshot 2024-01-07 at 20 22 06

But if the function returning the Promise subclass is used, the ordering is lost: Screenshot 2024-01-07 at 20 22 58

🙂 Expected behavior

The methods declared on the Promise and its subclasses / subinterfaces should show up before the "after adding await" properties of whatever is contained in the Promise.

Additional information about the issue

I'd be willing to work on fixing this with some guidance, if it's feasible.

贡献者指南