@@ -23,18 +23,19 @@ declare type StringDict = {
2323//
2424////////////////////////////////////////////////////////////////////////////////
2525
26- interface GmailTracker {
26+ interface GmailTracker < T extends string = never > {
27+ dom_observers : { [ observer in GmailDomObserver | T ] ?: DomObserverConfig } ;
2728 globals : any [ ] ;
2829 view_data : any [ ] ;
2930 ik : string ;
3031 hangouts : any ;
3132 events : { } [ ] ;
3233 actions : { } [ ] ;
3334 watchdog : {
34- before : { } ,
35- on : { } ,
36- after : { } ,
37- dom : { }
35+ before : { [ action in GmailBindAction | T ] ?: Function [ ] } ;
36+ on : { [ action in GmailBindAction | T ] ?: Function [ ] } ;
37+ after : { [ action in GmailBindAction | T ] ?: Function [ ] } ;
38+ dom : { [ observer in GmailDomObserver | T ] ?: Function [ ] } ;
3839 } ;
3940}
4041
@@ -55,9 +56,9 @@ declare type GmailPageType =
5556declare type GmailEmailAddress = string [ ] ;
5657
5758declare type GmailDomComposeRecipients = {
58- to : string [ ] ;
59- cc : string [ ] ;
60- bcc : string [ ] ;
59+ to : string [ ] ;
60+ cc : string [ ] ;
61+ bcc : string [ ] ;
6162}
6263
6364declare type GmailAttachmentDetails = {
@@ -489,7 +490,7 @@ interface GmailDomEmail {
489490
490491declare type GmailDomComposeLookup =
491492 'to' | 'cc' | 'bcc' | 'id' | 'draft' | 'subject' | 'subjectbox'
492- | 'all_subjects' | 'body' | 'quoted_reply' | 'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc' ;
493+ | 'all_subjects' | 'body' | 'quoted_reply' | 'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc' ;
493494
494495interface GmailMessageRow {
495496 summary : string ;
@@ -671,7 +672,7 @@ interface GmailTools {
671672 observes every element inserted into the DOM by Gmail and looks at the classes on those elements,
672673 checking for any configured observers related to those classes
673674 */
674- insertion_observer ( target : HTMLElement | string , dom_observers : any , dom_observer_map : any , sub : any ) : void ;
675+ insertion_observer ( target : HTMLElement | string , dom_observers : { [ observer : string ] : DomObserverConfig } , dom_observer_map : { [ className : string ] : string [ ] } , sub ?: string ) : void ;
675676
676677 make_request ( link : string , method : GmailHttpRequestMethod , disable_cache : boolean ) : string ;
677678 make_request_async ( link : string , method : GmailHttpRequestMethod , callback : ( data : string ) => void , disable_cache : boolean ) : void ;
@@ -718,11 +719,11 @@ interface GmailTools {
718719 add_right_toolbar_button ( content_html : string , onClickFunction : Function , styleClass : string ) : JQuery ;
719720 add_compose_button ( composeWindow : GmailDomCompose , content_html : string , onClickFunction : Function , styleClass ?: string ) : JQuery ;
720721 add_more_send_option (
721- composeWindow : GmailDomCompose ,
722- buttonText : string ,
723- onClickFunction : Function ,
724- styleClass ?: string | undefined ,
725- imgClass ?: string | undefined
722+ composeWindow : GmailDomCompose ,
723+ buttonText : string ,
724+ onClickFunction : Function ,
725+ styleClass ?: string | undefined ,
726+ imgClass ?: string | undefined
726727 ) : JQuery ;
727728 /**
728729 adds a button to an email attachment.
@@ -764,23 +765,25 @@ declare type GmailBindAction =
764765 | 'new_email' | 'refresh' | 'open_email' | 'upload_attachment' | 'compose'
765766 | 'compose_cancelled' | 'recipient_change' | 'view_thread' | 'view_email'
766767 | 'load_email_menu' ;
768+ declare type GmailDomObserver =
769+ 'view_thread' | 'view_email' | 'load_email_menu' | 'recipient_change' | 'compose'
767770
768771interface HttpEventRequestParams {
769- url : object ,
770- url_raw : string ;
771- body : string ;
772- body_params : object ;
773- method : string ;
772+ url : object ,
773+ url_raw : string ;
774+ body : string ;
775+ body_params : object ;
776+ method : string ;
774777}
775778
776779interface DomObserverConfig {
777- class : string | string [ ] ;
778- selector ?: string ;
779- sub_selector ?: string ;
780- handler ?: Function ;
781- }
780+ class : string | string [ ] ;
781+ selector ?: string ;
782+ sub_selector ?: string ;
783+ handler ?: Function ;
784+ }
782785
783- interface GmailObserve < T extends string = never > {
786+ interface GmailObserve < T extends string = never > {
784787 /**
785788 After an observer has been bound through gmail.observe.bind() (via a
786789 call to events gmail.observe.before(), gmail.observe.on(), or
@@ -798,7 +801,7 @@ interface GmailObserve<T extends string=never> {
798801 /**
799802 Bind a specified callback to an array of callbacks against a specified type & action
800803 */
801- bind ( type : GmailBindType , action : Function , callback : Function ) : void ;
804+ bind ( type : GmailBindType , action : GmailBindAction | T , callback : Function ) : void ;
802805
803806 /**
804807 an on event is observed just after gmail sends an xhr request
@@ -850,11 +853,11 @@ interface GmailObserve<T extends string=never> {
850853 Trigger any specified events bound to the passed type
851854 Returns true or false depending if any events were fired
852855 */
853- trigger ( type : GmailBindType , events : any , xhr : XMLHttpRequest ) : boolean ;
856+ trigger ( type : GmailBindType , events : { [ action in GmailBindAction | T ] ?: any [ ] } , xhr : XMLHttpRequest ) : boolean ;
854857 /**
855858 Trigger any specified DOM events passing a specified element & optional handler
856859 */
857- trigger_dom ( observer : any , element : HTMLElement , handler ?: Function ) : void ;
860+ trigger_dom ( observer : GmailDomObserver | T , element : HTMLElement , handler ?: Function ) : void ;
858861
859862 initialize_dom_observers ( ) : void ;
860863
@@ -867,7 +870,7 @@ interface GmailObserve<T extends string=never> {
867870 className / args - for a simple observer, this arg can simply be the class on an inserted DOM element that identifies this event should be
868871 triggered. For a more complicated observer, this can be an object containing properties for each of the supported DOM observer config arguments
869872 */
870- register ( action : string , args : string | DomObserverConfig ) : void ;
873+ register ( action : T , args : string | DomObserverConfig ) : void ;
871874 /**
872875 Observe DOM nodes being inserted. When a node with a class defined in api.tracker.dom_observers is inserted,
873876 trigger the related event and fire off any relevant bound callbacks
@@ -1030,15 +1033,15 @@ interface GmailCache {
10301033//
10311034////////////////////////////////////////////////////////////////////////////////
10321035
1033- declare class Gmail < T extends string = never > {
1034- constructor ( localJQuery ? : JQueryStatic ) ;
1036+ declare class Gmail < T extends string = never > {
1037+ constructor ( localJQuery : JQueryStatic | false ) ;
10351038
10361039 version : string ;
10371040 /**
10381041 These are some of the variables that are tracked and kept in
10391042 memory while the rest of the methods are in use.
10401043 */
1041- tracker : GmailTracker ;
1044+ tracker : GmailTracker < T > ;
10421045 get : GmailGet ;
10431046 check : GmailCheck ;
10441047 /**
0 commit comments