Skip to content

Commit

Permalink
adding [Add]EventListenerOptions parameter for generated signatures
Browse files Browse the repository at this point in the history
For the signatures generated within TS.fsx:
* Changes the type of the third argument to `boolean | AddEventListenerOptions` for `addEventListener`
* Changes the type of the third argument to `boolean | EventListenerOptions` for `removeEventListener`

Additionally, there were a few changes in addedTypes.json that needed to be updated by adding `removeEventListener` signatures and updating both `addEventListener` and `removeEventListener` to allow options:
* BroadcastChannel
* IDBDatabase

microsoft/TypeScript#18136
  • Loading branch information
Adam J. Hines committed Oct 26, 2017
1 parent 52a91ba commit c0cb9d9
Show file tree
Hide file tree
Showing 4 changed files with 884 additions and 862 deletions.
11 changes: 7 additions & 4 deletions TS.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -1066,18 +1066,21 @@ module Emit =
| _ -> ()

let EmitEventHandlers (flavor: Flavor) (prefix: string) (i:Browser.Interface) =
let getOptionsType (addOrRemove: string) =
if addOrRemove = "add" then "AddEventListenerOptions" else "EventListenerOptions"

let fPrefix =
if prefix.StartsWith "declare var" then "declare function " else ""

let emitTypedEventHandler (prefix: string) (addOrRemove: string) (iParent:Browser.Interface) =
Pt.Printl
"%s%sEventListener<K extends keyof %sEventMap>(type: K, listener: (this: %s, ev: %sEventMap[K]) => any, useCapture?: boolean): void;"
prefix addOrRemove iParent.Name i.Name iParent.Name
"%s%sEventListener<K extends keyof %sEventMap>(type: K, listener: (this: %s, ev: %sEventMap[K]) => any, options?: boolean | %s): void;"
prefix addOrRemove iParent.Name i.Name iParent.Name (getOptionsType addOrRemove)

let emitStringEventHandler (addOrRemove: string) =
Pt.Printl
"%s%sEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;"
fPrefix addOrRemove
"%s%sEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | %s): void;"
fPrefix addOrRemove (getOptionsType addOrRemove)

let tryEmitTypedEventHandlerForInterface (addOrRemove: string) =
if iNameToEhList.ContainsKey i.Name && not iNameToEhList.[i.Name].IsEmpty then
Expand Down
Loading

0 comments on commit c0cb9d9

Please sign in to comment.