Skip to content

Inserting intersections with 'Function' while narrowing breaks code #26970

Open
@DanielRosenwasser

Description

@DanielRosenwasser

@ahejlsberg and I ran into something like this in the RWC. This currently repros on the nightlies.

function foo(x: Object | (() => string)) {
    if (typeof x === "function") {
        // Previously had no errors
        x();
    }
}

Expected: No error

Actual:

[ts] Cannot invoke an expression whose type lacks a call signature. Type '(() => string) | (Object & Function)' has no compatible call signatures.

Potentially related to #25243.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureBreaking ChangeWould introduce errors in existing codeSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions