Skip to content

Commit

Permalink
[node] fix forward declaration of SharedArrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarna committed Feb 28, 2019
1 parent e861d26 commit 4fbfe7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions types/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
// TypeScript 2.1-specific augmentations:

// Forward-declarations for needed types from es2015 and later (in case users are using `--lib es5`)
// Empty interfaces are used here which merge fine with the real declarations in the lib XXX files
// just to ensure the names are known and node typings can be sued without importing these libs.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
Expand All @@ -72,8 +75,9 @@ interface SymbolConstructor {
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
declare class SharedArrayBuffer {
constructor(byteSize: number);
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
Expand Down
3 changes: 2 additions & 1 deletion types/node/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const result2 = Buffer.concat([utf8Buffer, base64Buffer], 9999999);
const arrUint8: Uint8Array = new Uint8Array(2);
const buf5: Buffer = Buffer.from(arrUint8);
const buf6: Buffer = Buffer.from(buf1);
const buf7: Buffer = Buffer.from(new SharedArrayBuffer(123));
const sb: SharedArrayBuffer = {} as any;
const buf7: Buffer = Buffer.from(sb);
}

// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
Expand Down

0 comments on commit 4fbfe7c

Please sign in to comment.