Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
0815fox opened this issue Oct 24, 2016 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@0815fox
Copy link

0815fox commented Oct 24, 2016

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.

@ahejlsberg
Copy link
Member

This is the same issue as #10025.

@0815fox
Copy link
Author

0815fox commented Oct 24, 2016

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
Copy link
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.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 24, 2016
@mhegazy mhegazy closed this as completed Oct 24, 2016
@0815fox
Copy link
Author

0815fox commented Oct 25, 2016

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?

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants