Skip to content

Experiment with elaborating member-wise when assigning to union types #35248

Description

@DanielRosenwasser
interface Stuff {
  a?: () => Promise<number[]>;
  b: () => Promise<string>;
  c: () => Promise<string>;
  d: () => Promise<string>;
  e: () => Promise<string>;
  f: () => Promise<string>;
  g: () => Promise<string>;
  h: () => Promise<string>;
  i: () => Promise<string>;
  j: () => Promise<string>;
  k: () => Promise<number>;
}

function foo(): Stuff | string {
  return {
    a() { return [123] },
    b: () => "hello",
    c: () => "hello",
    d: () => "hello",
    e: () => "hello",
    f: () => "hello",
    g: () => "hello",
    h: () => "hello",
    i: () => "hello",
    j: () => "hello",
    k: () => 123
  }
}

If you remove the | string from foo's return type, you'll get a much better set of error messages and spans. @amcasey ran into this while trying to do a refactor of our codebase to async hosts, and it made life very difficult.

Metadata

Metadata

Assignees

Labels

Domain: Error MessagesThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions