title: TypeScript determine type click handler will return
body: <p>I have a custom button control who's click handler can return a promise or void as below:</p>
  
  <pre><code>// --- Options for button control
  export interface buttonOptions {
     aProperty: string
     anotherProperty: number
     onClick: Promise&lt;IButtonClickResult&gt; | void
  }
  
  // --- Click handler added for click event inside control class
  protected clickHandler(): Promise&lt;IButtonClickResult&gt; | void {
     if(returnsPromise) displaySpinner()
  
     various operations
  
     this.options.onClick(this)
  }
  </code></pre>
  
  <p>The control is created using the builder pattern so it would be created as such:</p>
  
  <pre><code>buttonClass.build()
    .options({
        aProperty: 'Hope this works',
        anotherProperty: 1,
        onClick: () =&gt; {
            return new Promise&lt;IButtonClickResult&gt;((resolve, reject) =&gt; {         
  
              // --- I suppose I could pass reference to resolve or reject to async function and allow that function to resolve or reject the promise
              asyncOperation(resolve, reject)                         
            }).then((result) =&gt; button.onClickSuccess(result)).catch((error) =&gt; button.onclickError(error))
  </code></pre>
  
  <p>onClick could also be assigned a function that returns void as:</p>
  
  <pre><code>console.log('I was clicked')
  </code></pre>
  
  <p>If the click handler returns a promise, I want to add a spinner to the button until the promise resolves or rejects, then I will replace the spinner with the original button content through .then or maybe an oops through .catch</p>
  
  <p>My question is how to determine if a promise will be returned inside the button's click handler so I will know whether or not to display a spinner on the button. </p>
  
  <p>Any help is greatly appreciated. I have attempted typeof and instanceof, but to no avail. Potentially I was not using them correctly? My apologies, I am fairly new to TypeScript and NodeJS.</p>