Skip to content

Commit 8d6230f

Browse files
authored
Merge pull request microsoft#352 from saschanaz/callbackinterface
Fix callback interfaces
2 parents 07f2f3b + a6000f9 commit 8d6230f

File tree

5 files changed

+456
-497
lines changed

5 files changed

+456
-497
lines changed

TS.fsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ module Emit =
684684
| "DOMString" -> "string"
685685
| "DOMTimeStamp" -> "number"
686686
| "EndOfStreamError" -> "number"
687-
| "EventListener" -> "EventListenerOrEventListenerObject"
688687
| "double" | "float" -> "number"
689688
| "object" -> "any"
690689
| "ReadyState" -> "string"
@@ -838,11 +837,14 @@ module Emit =
838837
(if p.Variadic then "[]" else "")
839838
String.Join(", ", (List.map paramToString ps))
840839

841-
let EmitCallBackInterface (i:Browser.Interface) =
842-
Pt.Printl "interface %s {" i.Name
843-
Pt.PrintWithAddedIndent "(evt: Event): void;"
844-
Pt.Printl "}"
845-
Pt.Printl ""
840+
let EmitCallBackInterface flavor (i:Browser.Interface) =
841+
if ShouldKeep flavor i then
842+
let m = i.Methods.Value.Methods.[0]
843+
let overload = (GetOverloads (Function.Method m) false).[0]
844+
let paramsString = ParamsToString overload.ParamCombinations
845+
let returnType = DomTypeToTsType m.Type
846+
Pt.Printl "type %s = (%s) => %s | { %s(%s): %s; };" i.Name paramsString returnType m.Name.Value paramsString returnType
847+
Pt.Printl ""
846848

847849
let EmitCallBackFunctions flavor =
848850
let emitCallbackFunctionsFromJson (cb: InputJson.InputJsonType.Root) =
@@ -1064,7 +1066,7 @@ module Emit =
10641066

10651067
let emitStringEventHandler (addOrRemove: string) =
10661068
Pt.Printl
1067-
"%s%sEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | %s): void;"
1069+
"%s%sEventListener(type: string, listener: EventListener, options?: boolean | %s): void;"
10681070
fPrefix addOrRemove (getOptionsType addOrRemove)
10691071

10701072
let tryEmitTypedEventHandlerForInterface (addOrRemove: string) =
@@ -1484,15 +1486,12 @@ module Emit =
14841486
Pt.Printl ""
14851487

14861488
EmitDictionaries flavor
1487-
browser.CallbackInterfaces.Interfaces |> Array.iter EmitCallBackInterface
1489+
browser.CallbackInterfaces.Interfaces |> Array.iter (EmitCallBackInterface flavor)
14881490
EmitNonCallbackInterfaces flavor
14891491

14901492
// Add missed interface definition from the spec
14911493
InputJson.getAddedItems InputJson.Interface flavor |> Array.iter EmitAddedInterface
14921494

1493-
Pt.Printl "declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;"
1494-
Pt.Printl ""
1495-
14961495
EmitCallBackFunctions flavor
14971496

14981497
if flavor <> Worker then

0 commit comments

Comments
 (0)