Typecheck sources/AddSourceMapURLDialog.js with TypeScript

[email protected]

Bug: 1011811
Change-Id: I2088e7ba0c91f2cb56a5eee4cb9833119ea0f96f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2450033
Commit-Queue: Tim van der Lippe <[email protected]>
Auto-Submit: Tim van der Lippe <[email protected]>
Reviewed-by: Paul Lewis <[email protected]>
diff --git a/front_end/sources/AddSourceMapURLDialog.js b/front_end/sources/AddSourceMapURLDialog.js
index 9020766..be4efd5 100644
--- a/front_end/sources/AddSourceMapURLDialog.js
+++ b/front_end/sources/AddSourceMapURLDialog.js
@@ -2,9 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// @ts-nocheck
-// TODO(crbug.com/1011811): Enable TypeScript compiler checks
-
 import * as Common from '../common/common.js';
 import * as UI from '../ui/ui.js';
 
@@ -13,7 +10,7 @@
  */
 export class AddSourceMapURLDialog extends UI.Widget.HBox {
   /**
-   * @param {function(string)} callback
+   * @param {function(string):void} callback
    */
   constructor(callback) {
     super(/* isWebComponent */ true);
@@ -31,13 +28,7 @@
     this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent);
     this._dialog.setDefaultFocusedElement(this._input);
 
-    /**
-     * @this {AddSourceMapURLDialog}
-     */
-    this._done = function(value) {
-      this._dialog.hide();
-      callback(value);
-    };
+    this._callback = callback;
   }
 
   /**
@@ -45,9 +36,21 @@
    */
   show() {
     super.show(this._dialog.contentElement);
+    // UI.Dialog extends GlassPane and overrides the `show` method with a wider
+    // accepted type. However, TypeScript uses the supertype declaration to
+    // determine the full type, which requires a `!Document`.
+    // @ts-ignore
     this._dialog.show();
   }
 
+  /**
+   * @param {string} value
+   */
+  _done(value) {
+    this._dialog.hide();
+    this._callback(value);
+  }
+
   _apply() {
     this._done(this._input.value);
   }
diff --git a/front_end/ui/Dialog.js b/front_end/ui/Dialog.js
index d39421fd..3cdfa26 100644
--- a/front_end/ui/Dialog.js
+++ b/front_end/ui/Dialog.js
@@ -74,7 +74,7 @@
 
   /**
    * @override
-   * @param {!Document|!Element=} where
+   * @param {(!Document|!Element)=} where
    */
   show(where) {
     const document = /** @type {!Document} */ (
diff --git a/front_end/ui/UIUtils.js b/front_end/ui/UIUtils.js
index f109e0f..89d6e63 100644
--- a/front_end/ui/UIUtils.js
+++ b/front_end/ui/UIUtils.js
@@ -1242,7 +1242,7 @@
 /**
  * @param {string=} className
  * @param {string=} type
- * @return {!Element}
+ * @return {!HTMLInputElement}
  */
 export function createInput(className, type) {
   const element = document.createElement('input');
@@ -1254,7 +1254,7 @@
   if (type) {
     element.type = type;
   }
-  return element;
+  return /** @type {!HTMLInputElement} */ (element);
 }
 
 /**