Robert
Robert

Reputation: 2691

Vue and Typescript Type 'HTMLElement' is not assignable to type

I have Vue component. In data() I declared variable to store selected row

data() {
    return {
      selectedTableElemRow: null,

and then in methods I try to assign selected row to this variable:

let tableElemRow = tableElementCell.parentElement;
if (tableElemRow != null) {
   if (!this.isTableRowElement(tableElemRow)) {
      tableElemRow = tableElemRow.parentElement;
   }
 }

 if (tableElemRow != null) {
    this.selectedTableElemRow = tableElemRow as HTMLTableRowElement;
 }

And I get error:

Severity    Code    Description Project File    Line    Suppression State
Error   TS2322  (TS) Type 'HTMLTableRowElement' is not assignable to type '{ new (): HTMLTableRowElement; prototype: HTMLTableRowElement; }'.   ClientApp (tsconfig project)    

Upvotes: 1

Views: 3478

Answers (1)

Robert
Robert

Reputation: 2691

The declaration of the variable should be:

data() {
    return {
      selectedTableElemRow: null as any,

Upvotes: 2

Related Questions