在 TypeScript 中声明 UInt8Array 变量
Declare UInt8Array variable in TypeScript
如何在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());
});
我有一个错误:
error TS2304: Cannot find name 'UInt8Array'
谢谢
以下实例适用于 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);
您的错误消息表明存在拼写错误,即
error TS2304: Cannot find name 'UInt8Array'
抱怨UInt8Array
。但您要查找的名称可能是 Uint8Array,小写 i
.
如何在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());
});
我有一个错误:
error TS2304: Cannot find name 'UInt8Array'
谢谢
以下实例适用于 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);
您的错误消息表明存在拼写错误,即
error TS2304: Cannot find name 'UInt8Array'
抱怨UInt8Array
。但您要查找的名称可能是 Uint8Array,小写 i
.