我正在尝试使用 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)