Skip to content

Seek most-overlapping types when relating object types in unions #26450

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

From @rkirov at DefinitelyTyped/DefinitelyTyped#28044 (comment)

interface A {
    a: string;
    b: number
};

interface Other {
    o: number;
}

declare function f(x: A | Other): any;

export let x = { a: '', b: '' };
export let y = f(x);

Expected

Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Other | A'.
  Type '{ a: string; b: string; }' is not assignable to type 'A'.
    Types of property 'b' are incompatible.
      Type 'string' is not assignable to type 'number'.

Actual

Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'A | Other'.
  Type '{ a: string; b: string; }' is not assignable to type 'Other'.
    Property 'o' is missing in type '{ a: string; b: string; }'.

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions