html-externs icon indicating copy to clipboard operation
html-externs copied to clipboard

Use new function type syntax

Open markknol opened this issue 3 years ago • 0 comments

It would be great if we could support the new function type since this would provide richer completion/documentation for the working with JavaScript. I noticed this information is already available in the webidls.

For example; BaseAudioContext webidl:

callback DecodeSuccessCallback = void (AudioBuffer decodedData);
callback DecodeErrorCallback = void (DOMException error);

...

Promise<AudioBuffer> decodeAudioData(ArrayBuffer audioData,
                                         optional DecodeSuccessCallback successCallback,
                                         optional DecodeErrorCallback errorCallback);

Currently we generate:

function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:AudioBuffer->Void, ?errorCallback:js.html.DOMException->Void):Promise<AudioBuffer>;

This could be improved like this:

function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:(decodedData:AudioBuffer) -> Void,
		?errorCallback:(error:DOMException) -> Void):Promise<AudioBuffer>;

.. or with typedef

function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:DecodeSuccessCallback, ?errorCallback:DecodeErrorCallback):Promise<AudioBuffer>;

typedef DecodeSuccessCallback = (decodedData:AudioBuffer) -> Void;
typedef DecodeErrorCallback = (error:DOMException) -> Void;

If the info is not available we can always fallback to the "old syntax".

markknol avatar Sep 14 '20 08:09 markknol