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

Conditional types - Extract works incorrect  #22899

Description

@sirian

TypeScript Version: 2.8.0-rc, 2.9.0-dev.20180327

declare function isFunction<T>(value: T): value is Extract<T, Function>;

declare function toString1(value: object | Function): string ;
declare function toString2(value: Function): string ;

function foo<T>(value: T) {
    if (isFunction(value)) {
        toString1(value); // ok

        toString2(value); // error TS2345: Argument of type 'Extract<T, Function>' is not assignable to parameter of type 'Function'.
                          // Type 'T' is not assignable to type 'Function'.
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions