如何在TypeScript中声明类型为UInt8Array的函数参数?
import * as fs from "fs";
fs.readFile(fileName, (err: string, data: UInt8Array) => {
if (err) {
return console.error(err);
}
console.log("file text: " + data.toString());
});
我有错误:
错误TS2304:找不到姓名' UInt8Array'
由于
答案 0 :(得分:7)
答案 1 :(得分:-1)
以下实例化在TypeScript 1.6(编写本文时的最新稳定版本)中有效:
let t01 = new Uint8Array([1, 2, 3, 4]);
let t02 = new Int8Array([1, 2, 3, 4]);
let t03 = new Uint8Array([1, 2, 3, 4]);
let t04 = new Uint8ClampedArray([1, 2, 3, 4]);
let t05 = new Int16Array([1, 2, 3, 4]);
let t06 = new Uint16Array([1, 2, 3, 4]);
let t07 = new Int32Array([1, 2, 3, 4]);
let t08 = new Uint32Array([1, 2, 3, 4]);
let t09 = new Float32Array([1.5, 2.5, 3.5, 4.5]);
let t10 = new Float64Array([1.5, 2.5, 3.5, 4.5]);
let arrayBuffer = new ArrayBuffer(16);