Convert gr-confirm-revert-submission-dialog to typescript

The change converts the following files to typescript:

* elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts

Change-Id: I3132b807bde64eddfd78e51d903c3a4b98a5b1c1
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
index 87bc9a0..5f83a14 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
@@ -988,8 +988,7 @@
     this.$.restAPI.getChanges('', query)
         .then(changes => {
           this.$.confirmRevertSubmissionDialog.
-              _populateRevertSubmissionMessage(
-                  this.commitMessage, this.change, changes);
+              _populateRevertSubmissionMessage(this.change, changes);
           this._showActionDialog(this.$.confirmRevertSubmissionDialog);
         });
   }
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
index a639a61..9754e89 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
@@ -14,26 +14,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import '../../shared/gr-dialog/gr-dialog.js';
-import '../../../styles/shared-styles.js';
-import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
-import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
-import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
-import {PolymerElement} from '@polymer/polymer/polymer-element.js';
-import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html.js';
+import '../../shared/gr-dialog/gr-dialog';
+import '../../../styles/shared-styles';
+import '../../shared/gr-js-api-interface/gr-js-api-interface';
+import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
+import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
+import {PolymerElement} from '@polymer/polymer/polymer-element';
+import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html';
+import {customElement, property} from '@polymer/decorators';
+import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
+import {ChangeInfo} from '../../../types/common';
 
-const ERR_COMMIT_NOT_FOUND =
-    'Unable to find the commit hash of this change.';
+const ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
 const CHANGE_SUBJECT_LIMIT = 50;
 
-/**
- * @extends PolymerElement
- */
-class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
-    LegacyElementMixin(PolymerElement)) {
-  static get template() { return htmlTemplate; }
+export interface GrConfirmRevertSubmissionDialog {
+  $: {
+    jsAPI: JsApiService & Element;
+  };
+}
+@customElement('gr-confirm-revert-submission-dialog')
+export class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
+  LegacyElementMixin(PolymerElement)
+) {
+  static get template() {
+    return htmlTemplate;
+  }
 
-  static get is() { return 'gr-confirm-revert-submission-dialog'; }
   /**
    * Fired when the confirm button is pressed.
    *
@@ -46,69 +53,88 @@
    * @event cancel
    */
 
-  static get properties() {
-    return {
-      message: String,
-      commitMessage: String,
-    };
-  }
+  @property({type: String})
+  message?: string;
 
-  _getTrimmedChangeSubject(subject) {
+  @property({type: String})
+  commitMessage?: string;
+
+  _getTrimmedChangeSubject(subject: string) {
     if (!subject) return '';
     if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
     return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
   }
 
-  _modifyRevertSubmissionMsg(change) {
-    return this.$.jsAPI.modifyRevertSubmissionMsg(change,
-        this.message, this.commitMessage);
+  _modifyRevertSubmissionMsg(change?: ChangeInfo) {
+    if (!change || !this.message || !this.commitMessage) {
+      return this.message;
+    }
+    return this.$.jsAPI.modifyRevertSubmissionMsg(
+      change,
+      this.message,
+      this.commitMessage
+    );
   }
 
-  _populateRevertSubmissionMessage(message, change, changes) {
+  _populateRevertSubmissionMessage(
+    change?: ChangeInfo,
+    changes?: ChangeInfo[]
+  ) {
     if (change === undefined) {
       return;
     }
     // Follow the same convention of the revert
     const commitHash = change.current_revision;
     if (!commitHash) {
-      this.dispatchEvent(new CustomEvent('show-alert', {
-        detail: {message: ERR_COMMIT_NOT_FOUND},
-        composed: true, bubbles: true,
-      }));
+      this.dispatchEvent(
+        new CustomEvent('show-alert', {
+          detail: {message: ERR_COMMIT_NOT_FOUND},
+          composed: true,
+          bubbles: true,
+        })
+      );
       return;
     }
-    const submissionId = change.submission_id;
-    const revertTitle = 'Revert submission ' + submissionId;
-    this.changes = changes;
-    this.message = revertTitle + '\n\n' +
-        'Reason for revert: <INSERT REASONING HERE>\n';
+    const revertTitle = `Revert submission ${change.submission_id}`;
+    this.message =
+      revertTitle + '\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n';
     changes = changes || [];
     if (changes.length) {
       this.message += 'Reverted Changes:\n';
       changes.forEach(change => {
-        this.message += change.change_id.substring(0, 10) + ': ' +
-          this._getTrimmedChangeSubject(change.subject) + '\n';
+        this.message +=
+          `${change.change_id.substring(0, 10)}: ` +
+          `${this._getTrimmedChangeSubject(change.subject)}\n`;
       });
     }
     this.message = this._modifyRevertSubmissionMsg(change);
   }
 
-  _handleConfirmTap(e) {
+  _handleConfirmTap(e: Event) {
     e.preventDefault();
     e.stopPropagation();
-    this.dispatchEvent(new CustomEvent('confirm', {
-      composed: true, bubbles: false,
-    }));
+    this.dispatchEvent(
+      new CustomEvent('confirm', {
+        composed: true,
+        bubbles: false,
+      })
+    );
   }
 
-  _handleCancelTap(e) {
+  _handleCancelTap(e: Event) {
     e.preventDefault();
     e.stopPropagation();
-    this.dispatchEvent(new CustomEvent('cancel', {
-      composed: true, bubbles: false,
-    }));
+    this.dispatchEvent(
+      new CustomEvent('cancel', {
+        composed: true,
+        bubbles: false,
+      })
+    );
   }
 }
 
-customElements.define(GrConfirmRevertSubmissionDialog.is,
-    GrConfirmRevertSubmissionDialog);
+declare global {
+  interface HTMLElementTagNameMap {
+    'gr-confirm-revert-submission-dialog': GrConfirmRevertSubmissionDialog;
+  }
+}
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
index e2f2e9e..1ed799f 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog_test.js
@@ -40,7 +40,6 @@
   test('single line', () => {
     assert.isNotOk(element.message);
     element._populateRevertSubmissionMessage(
-        'one line commit\n\nChange-Id: abcdefg\n',
         {current_revision: 'abcd123', submission_id: '111'});
     const expected = 'Revert submission 111\n\n' +
       'Reason for revert: <INSERT REASONING HERE>\n';
@@ -50,7 +49,6 @@
   test('multi line', () => {
     assert.isNotOk(element.message);
     element._populateRevertSubmissionMessage(
-        'many lines\ncommit\n\nmessage\n\nChange-Id: abcdefg\n',
         {current_revision: 'abcd123', submission_id: '111'});
     const expected = 'Revert submission 111\n\n' +
       'Reason for revert: <INSERT REASONING HERE>\n';
@@ -60,7 +58,6 @@
   test('issue above change id', () => {
     assert.isNotOk(element.message);
     element._populateRevertSubmissionMessage(
-        'test \nvery\n\ncommit\n\nBug: Issue 42\nChange-Id: abcdefg\n',
         {current_revision: 'abcd123', submission_id: '111'});
     const expected = 'Revert submission 111\n\n' +
         'Reason for revert: <INSERT REASONING HERE>\n';
@@ -70,7 +67,6 @@
   test('revert a revert', () => {
     assert.isNotOk(element.message);
     element._populateRevertSubmissionMessage(
-        'Revert "one line commit"\n\nChange-Id: abcdefg\n',
         {current_revision: 'abcd123', submission_id: '111'});
     const expected = 'Revert submission 111\n\n' +
       'Reason for revert: <INSERT REASONING HERE>\n';
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
index 4b597a5..3d2d71b 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts
@@ -33,5 +33,10 @@
 export interface JsApiService {
   getElement(key: TargetElement): HTMLElement;
   addEventCallback(eventName: EventType, callback: EventCallback): void;
+  modifyRevertSubmissionMsg(
+    change: ChangeInfo,
+    revertSubmissionMsg: string,
+    origMsg: string
+  ): string;
   // TODO(TS): Add more methods when needed for the TS conversion.
 }