Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(dts): array buffer types (ES2024,ES2017)
Co-authored-by: Indrajeet Nikam <indrajitbnikam@gmail.com>
  • Loading branch information
santi-mir and indrajitbnikam committed Mar 21, 2024
commit d5917179152511344eae1a7a8fae435383e86bc9
3 changes: 3 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ const libEntries: [string, string][] = [
["es2017.string", "lib.es2017.string.d.ts"],
["es2017.intl", "lib.es2017.intl.d.ts"],
["es2017.typedarrays", "lib.es2017.typedarrays.d.ts"],
["es2017.arraybuffer", "lib.es2017.arraybuffer.d.ts"],
["es2017.dataview", "lib.es2017.dataview.d.ts"],
["es2018.asyncgenerator", "lib.es2018.asyncgenerator.d.ts"],
["es2018.asynciterable", "lib.es2018.asynciterable.d.ts"],
["es2018.intl", "lib.es2018.intl.d.ts"],
Expand Down Expand Up @@ -234,6 +236,7 @@ const libEntries: [string, string][] = [
["esnext.decorators", "lib.esnext.decorators.d.ts"],
["esnext.object", "lib.esnext.object.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.arraybuffer", "lib.esnext.arraybuffer.d.ts"],
["esnext.regexp", "lib.esnext.regexp.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],
Expand Down
3 changes: 3 additions & 0 deletions src/lib/es2017.arraybuffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface ArrayBufferConstructor {
new (): ArrayBuffer;
}
2 changes: 2 additions & 0 deletions src/lib/es2017.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// <reference lib="es2016" />
/// <reference lib="es2017.object" />
/// <reference lib="es2017.sharedmemory" />
/// <reference lib="es2017.arraybuffer" />
/// <reference lib="es2017.dataview" />
/// <reference lib="es2017.string" />
/// <reference lib="es2017.intl" />
/// <reference lib="es2017.typedarrays" />
Expand Down
3 changes: 3 additions & 0 deletions src/lib/es2017.dataview.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface DataViewConstructor {
new (): DataView;
}
4 changes: 2 additions & 2 deletions src/lib/es2017.sharedmemory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ interface SharedArrayBuffer {
/**
* Returns a section of an SharedArrayBuffer.
*/
slice(begin: number, end?: number): SharedArrayBuffer;
slice(begin?: number, end?: number): SharedArrayBuffer;
readonly [Symbol.species]: SharedArrayBuffer;
readonly [Symbol.toStringTag]: "SharedArrayBuffer";
}

interface SharedArrayBufferConstructor {
readonly prototype: SharedArrayBuffer;
new (byteLength: number): SharedArrayBuffer;
new (byteLength?: number): SharedArrayBuffer;
}
declare var SharedArrayBuffer: SharedArrayBufferConstructor;

Expand Down
53 changes: 53 additions & 0 deletions src/lib/esnext.arraybuffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
interface ArrayBuffer {
/**
* If this ArrayBuffer is resizable, returns the maximum byte length given during construction; returns the byte length if not.
*/
get maxByteLength(): number;
/**
* Returns true if this ArrayBuffer can be resized.
*/
get resizable(): boolean;

/**
* Resizes the ArrayBuffer to the specified size (in bytes).
* @param newByteLength The new length, in bytes, to resize the ArrayBuffer to.
*/
resize(newByteLength: number): undefined;
}

Comment on lines +1 to +17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are other methods and properties that need to be added. Like this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached

interface ArrayBufferOptions {
maxByteLength?: number;
}

interface ArrayBufferConstructor {
new(byteLength?: number, options?: ArrayBufferOptions): ArrayBuffer;
}

interface SharedArrayBuffer {
/**
* Returns true if this SharedArrayBuffer can grow.
*/
get growable(): number;

/**
* If this SharedArrayBuffer is growable, returns the maximum byte length given during construction; returns the byte length if not.
*/
get maxByteLength(): number;

/**
* Grows the SharedArrayBuffer to the specified size (in bytes).
* @param newByteLength The new length, in bytes, to resize the SharedArrayBuffer to.
*/
grow(newByteLength: number): undefined;
}

interface SharedArrayBufferOptions {
maxByteLength?: number;
}

interface SharedArrayBufferConstructor {
new(
byteLength?: number,
options?: SharedArrayBufferOptions,
): SharedArrayBuffer;
}
1 change: 1 addition & 0 deletions src/lib/esnext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/// <reference lib="esnext.collection" />
/// <reference lib="esnext.array" />
/// <reference lib="esnext.regexp" />
/// <reference lib="esnext.arraybuffer" />
5 changes: 4 additions & 1 deletion src/lib/libs.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"es2017.string",
"es2017.intl",
"es2017.typedarrays",
"es2017.dataview",
"es2017.arraybuffer",
"es2018.asyncgenerator",
"es2018.asynciterable",
"es2018.regexp",
Expand Down Expand Up @@ -79,6 +81,7 @@
"esnext.collection",
"esnext.array",
"esnext.regexp",
"esnext.arraybuffer",
"decorators",
"decorators.legacy",
// Default libraries
Expand All @@ -104,4 +107,4 @@
"es5.full": "lib.d.ts",
"es2015.full": "lib.es6.d.ts"
}
}
}