HaxeFoundation / HaxeFoundation/html-externs

Use new function type syntax

Open
#18 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
IDL
Stars
16
Forks
5
PR merge metrics
No merged PRs in 30d

Description

It would be great if we could support the [new function type](https://github.com/HaxeFoundation/haxe-evolution/blob/master/proposals/0003-new-function-type.md) 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](https://github.com/HaxeFoundation/html-externs/blob/52a15145a2b036c389b422a7d694a90aaa7a66dd/webidl/mozilla/BaseAudioContext.webidl#L43-L45):
```idl
callback DecodeSuccessCallback = void (AudioBuffer decodedData);
callback DecodeErrorCallback = void (DOMException error);

...

Promise decodeAudioData(ArrayBuffer audioData,
optional DecodeSuccessCallback successCallback,
optional DecodeErrorCallback errorCallback);
```
Currently we generate:
```haxe
function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:AudioBuffer->Void, ?errorCallback:js.html.DOMException->Void):Promise;
```
This could be improved like this:
```haxe
function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:(decodedData:AudioBuffer) -> Void,
?errorCallback:(error:DOMException) -> Void):Promise;
```
.. or with typedef
```haxe
function decodeAudioData(audioData:js.lib.ArrayBuffer, ?successCallback:DecodeSuccessCallback, ?errorCallback:DecodeErrorCallback):Promise;

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

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.