Skip to content

Better errors relating callable/constructable types in unions #26449

@DanielRosenwasser

Description

@DanielRosenwasser

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

interface IDirectiveLinkFn<TScope> {
    (scope: TScope): void;
}

interface IDirectivePrePost<TScope> {
    pre?: IDirectiveLinkFn<TScope>;
    post?: IDirectiveLinkFn<TScope>;
}

export let blah: IDirectiveLinkFn<number> | IDirectivePrePost<number> = (x: string) => {}

Expected:

Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn<number>'.
  Types of parameters 'x' and 'scope' are incompatible.
    Type 'number' is not assignable to type 'string'.

Actual:

Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn<number> | IDirectivePrePost<number>'.
  Type '(x: string) => void' has no properties in common with type 'IDirectivePrePost<number>'.

Metadata

Metadata

Labels

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

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