Search code examples
typescripttsc

Overloaded Declaration Causes Build Error


I have supplied the overloaded declaration for postMessage to represent the message-only signature (rather than the lib.d.ts three-argument version).

declare function postMessage(message: any): void;

I get no visual errors, red squiggles etc, but I do get a build error.

Build: Supplied parameters do not match any signature of call target.

Build: Could not select overload for 'call' expression.

On this line:

postMessage(message);

Is this a bug in selecting the overload I supplied or am I doing something stupid?


Solution

  • Seems like a valid bug report for the compler. The following works fine:

    declare function foo(message: any, targetOrigin: string, ports?: any): void;
    declare function foo(message: any): void;
    
    foo('asdf');
    

    But the following will error on compile

    declare function postMessage(message: any): void;
    postMessage('asdf');
    

    Same for other functions at the root of lib.d.ts e.g.:

    declare function blur(message: any): void;
    blur('asdf');
    

    It is almost as if the declare isn't even parsed. The following gives the same error :

    postMessage('asdf');
    

    Momentary solution

    use the no-default-lib reference tag :

    /// <reference no-default-lib="true"/>
    declare function postMessage(message: any): void;
    postMessage('asdf');