ASDAlexander77 / TypeScriptCompiler

TypeScript Compiler (by LLVM)
MIT License
588 stars 28 forks source link

function generic constraint error #75

Closed mooooooi closed 10 months ago

mooooooi commented 11 months ago

error:

>.\tsc.exe --emit=jit --nogc .\main.ts
.\main.ts:4:5: warning: Type '!ts.class<@Abc, !ts.class_storage<@Abc>>' does not satisfy the constraint '!ts.iface<@IAbc>'.
    interfaceCall(abc);
    ^
.\main.ts:4:5: error: not all types could be inferred
    interfaceCall(abc);
    ^
.\main.ts:4:5: error: can't instantiate function. 'interfaceCall' not all generic types can be identified       
    interfaceCall(abc);
    ^
.\main.ts:1:1: error: failed statement
function main()

code:

function main()
{
    var abc = new Abc();
    interfaceCall(abc);
}

// but corret if 'function interfaceCall<TAbc extends ->Abc<->(aaa: TAbc) '
function interfaceCall<TAbc extends IAbc>(aaa: TAbc)
{
    aaa.ok();
}

interface IAbc
{
    ok(): void;
}

class Abc implements IAbc
{
    ok()
    {
        print("aaaa");
    }
}
ASDAlexander77 commented 11 months ago

aha, Yes, thank you, will have a look

ASDAlexander77 commented 11 months ago

but if you need working code you can remove " extends IAbc" and the compiler will not check constraints

ASDAlexander77 commented 10 months ago

fixed, will be released soon