Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将ValidatorJS isISIN转换为Typescript并获取错误?_Javascript_Typescript_Parseint - Fatal编程技术网

Javascript 将ValidatorJS isISIN转换为Typescript并获取错误?

Javascript 将ValidatorJS isISIN转换为Typescript并获取错误?,javascript,typescript,parseint,Javascript,Typescript,Parseint,将isin从validatorjs转换为typescript时,我遇到以下错误: (parameter) character: string No overload matches this call. The last overload gave the following error. Type 'number' is not assignable to type 'string'.ts(2769) lib.es5.d.ts(454, 53): The expected typ

isin
从validatorjs转换为typescript时,我遇到以下错误:


(parameter) character: string
No overload matches this call.
  The last overload gave the following error.
    Type 'number' is not assignable to type 'string'.ts(2769)
lib.es5.d.ts(454, 53): The expected type comes from the return type of this signature.
lib.es5.d.ts(454, 5): The last overload is declared here.
代码如下:

  const checksumStr = target.replace(/[A-Z]/g, character => (parseInt(character, 36)));

VSCOde在
(parseInt(字符,36))
下绘制一条红线,并显示错误

想法?是否应该不存在
parseInt

以下是整个方法,仅供参考:

/**
 * Test whether the target string is an ISBN number.
 * 
 * @param target The string
 * @return true if the `target` string is an ISIN number, false otherwise
 */
export function isISIN(target:string) {
  assertString(target);
  if (!isin.test(target)) {
    return false;
  }

  const checksumStr = target.replace(/[A-Z]/g, character => (parseInt(character, 36)));

  let sum = 0;
  let digit;
  let tmpNum;
  let shouldDouble = true;
  for (let i = checksumStr.length - 2; i >= 0; i--) {
    digit = checksumStr.substring(i, (i + 1));
    tmpNum = parseInt(digit, 10);
    if (shouldDouble) {
      tmpNum *= 2;
      if (tmpNum >= 10) {
        sum += tmpNum + 1;
      } else {
        sum += tmpNum;
      }
    } else {
      sum += tmpNum;
    }
    shouldDouble = !shouldDouble;
  }

  return parseInt(target.substr(target.length - 1), 10) === (10000 - sum) % 10;
}

这是因为返回一个
数字
,并期望收到一个
字符串
作为替换

无论如何,代码是有效的,这应该是一个警告

要修复它,请将parseInt结果转换为字符串。比如:

const replacer=character=>{
const intValue=parseInt(字符,36);
返回intValue?intValue.toString():“”
}
const checksumStr=target.replace(/[A-Z]/g,replace);