小编Ciz*_*zia的帖子

Typescript : .toString(16) - 错误 需要 0 个参数,但得到 1 个

我正在尝试使用 number.toString(16) 函数将数字转换为十六进制,但它给了我错误Error Expected 0 arguments, but got 1.

我的类型可能做错了,因为我相信它应该有效。

这是我的代码:

type ImageToEncode = {
  pixelsAndColors: string[][][];
  bounds: string[][][];
  paletteIndex: string;
}

task("encodeImage", "Encode an image", async function(taskArgs: ImageToEncode) {
  
  const hexPixelsAndColors = taskArgs.pixelsAndColors
  .map((array: string[][]) => {
      let firstChar = array[0].toString(16);
      let secondChar = array[1].toString(16);
      if(firstChar.length < 2) {
          firstChar = `0${firstChar}`;
      }
      if(secondChar.length < 2) {
          secondChar =`0${secondChar}`;
      }
      return [firstChar, secondChar];
  })
  .map((array: string[]) => array.join(""))
  .join("");

  const hexBounds = taskArgs.bounds.map(bound => {
    let firstChar …
Run Code Online (Sandbox Code Playgroud)

hex typescript

1
推荐指数
1
解决办法
2424
查看次数

标签 统计

hex ×1

typescript ×1