镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Better errors relating callable/constructable types in unions #26449

Closed

Description

From Rado Kirov (@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

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions