通用类型数组皮棉警告Array <>

时间:2019-02-03 13:40:17

标签: javascript arrays reactjs typescript

出现以下皮棉错误

<input id="hostname" name="hostname" type="text" value="BR0???" class="hostname"/>
<input id="comtest" name="comtest" type="text" class="commmunity"/>
<input id="comm_check1" name="comm_check1" type="checkbox"  onchange="f_set_comm()"/>

function f_set_comm() {

  //extract integers    
  var value = document.getElementById("hostname").value;
  var numbers = value.match(/\d+/g).map(Number);

  //add :9
  document.getElementById("comtest").value = numbers; 
  document.getElementById("comtest").value = document.getElementById("comtest").value + ":9";

  //check type and add 1 or 2 based on last char A or B in hostname
  if (value.substring(value.length-1)== "A")
    document.getElementById("comtest").value = document.getElementById("comtest").value + "1";

  if (value.substring(value.length-1)== "B")
    document.getElementById("comtest").value = document.getElementById("comtest").value + "2";

    if (!((value.substring(value.length-1)== "A")) && (!(value.substring(value.length-1)== "B")))
       document.getElementById("comtest").value = document.getElementById("comtest").value + "0";

      //remove all strings if unchecked
  if (!document.getElementById("comm_check1").checked)
    document.getElementById('comtest').value = '';

}

这是数组

Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
Replace generic-typed Array with array literal: Array<string>

如何解决此警告,我也尝试了其他方法,但仍然存在警告。

0 个答案:

没有答案