最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Declare UInt8Array variable in TypeScript - Stack Overflow

programmeradmin9浏览0评论

How to declare function parameter of type UInt8Array in TypeScript?

import * as fs from "fs";
fs.readFile(fileName, (err: string, data: UInt8Array) => {
                if (err) {
                    return console.error(err);
                }
                console.log("file text: " + data.toString());
            });

I'm having an error:

error TS2304: Cannot find name 'UInt8Array'

Thanks

How to declare function parameter of type UInt8Array in TypeScript?

import * as fs from "fs";
fs.readFile(fileName, (err: string, data: UInt8Array) => {
                if (err) {
                    return console.error(err);
                }
                console.log("file text: " + data.toString());
            });

I'm having an error:

error TS2304: Cannot find name 'UInt8Array'

Thanks

Share Improve this question asked Aug 1, 2016 at 21:27 Ulad MelekhUlad Melekh 9443 gold badges18 silver badges33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

Your error message indicates a typo, i.e.

error TS2304: Cannot find name 'UInt8Array'

complains about UInt8Array. But the name you're looking for is probably Uint8Array, with a lowercase i.

The following instantiations work in TypeScript 1.6 (the latest stable version at the time of writing):

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);

Declare TypedArray with ArrayLike?

发布评论

评论列表(0)

  1. 暂无评论