Skip to content

Breaking change from 1.8.10 to 2.0.3 for union types of class having functions #11814

Closed
@0815fox

Description

@0815fox

TypeScript Version: 2.0.3
Transferring my project from 1.8.10 to 2.0.3 ran me into a bunch of issues all similar to the following simplified code example (test.ts):

class X<T> {
    bla(x:()=>T|Z<T>) {

    }
}

class Y<T> {
    bla(x:()=>T) {

    }
}

class Z<T> {

}


function doBla<T>(In:T) {
    const x:X<T>|Y<T>|T = new X();
    if ((<X<T>|Y<T>>x).bla) (<X<T>|Y<T>>x).bla(()=>{return In;}); //<= compiles in 1.8.10, but fails in 2.0.3
}

Expected behavior: compiles (as on tsc 1.8.10)

Actual behavior: does not compile on 2.0.3, see below

mk@mk-actifsource:~/tmp$ tsc -v
Version 1.8.10
mk@mk-actifsource:~/tmp$ tsc test.ts
mk@mk-actifsource:~/tmp$ node_modules/.bin/tsc -v
Version 2.0.3
mk@mk-actifsource:~/tmp$ node_modules/.bin/tsc test.ts 
src/test.ts(20,26): error TS2349: Cannot invoke an expression whose type lacks a call signature.

I tried to search for similar issues and found #7294, however I am not sure about relevance of that issue.

Activity

ahejlsberg

ahejlsberg commented on Oct 24, 2016

@ahejlsberg
Member

This is the same issue as #10025.

0815fox

0815fox commented on Oct 24, 2016

@0815fox
Author

However, #10025 states milestone 2.0.2 - this report is for 2.0.3. Is it really the same issue, which is not yet completely fixed, or just related?

ahejlsberg

ahejlsberg commented on Oct 24, 2016

@ahejlsberg
Member

It is the same issue, and it is unfortunately an actual breaking change. As mentioned in the comments for #10025, it happened to work in some cases (including yours) because of aggressive subtype reduction, but we need a different approach to actually fix the issue in the general case.

0815fox

0815fox commented on Oct 25, 2016

@0815fox
Author

For others finding this ticket: the currently open ticket handling that case seems to be #9104.
BUT: #9104 is itself market as DUPLICATE as well, however, I cannot find, which "not closed" ticket #9104 actually duplicates.
Can you give us a pointer, which open ticket handles the type inference issue?

locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ahejlsberg@mhegazy@0815fox

        Issue actions

          Breaking change from 1.8.10 to 2.0.3 for union types of class having functions · Issue #11814 · microsoft/TypeScript