Skip to content

Show some elaboration for property not existing in union type #10256

Description

@RyanCavanaugh

I have some code like this, except there are about a dozen types instead of just three:

interface Foo {
  kind: "foo";
  name: string;
}
interface Bar {
  kind: "bar";
  name: string;
}
interface Qua {
  kind: "qua";
  length: string;
}

type FBQ = Foo | Bar | Qua;
let x: FBQ = <any>undefined;
console.log(x.name);

The error reported is

a.ts(16,15): error TS2339: Property 'name' does not exist on type 'FBQ'.

This is inactionable on a union type, especially when its consituents are hidden behind an alias. We should show something like

a.ts(16,15): error TS2339: Property 'name' does not exist on type 'FBQ'.
   Property 'name' does not exist on type 'Qua'

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    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