Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions types/node/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down
11 changes: 11 additions & 0 deletions types/node/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ const result2 = Buffer.concat([utf8Buffer, base64Buffer] as readonly Uint8Array[
Buffer.from({} as { [Symbol.toPrimitive](): number });
}

// ArrayLike or string
{
const arrayOrString = "foo" as number[] | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(arrayOrString);

const typedArrayOrString = "foo" as Uint8Array<ArrayBuffer> | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(typedArrayOrString);
}

// @ts-expect-error
Buffer.from({});
// @ts-expect-error
Expand Down
1 change: 1 addition & 0 deletions types/node/ts5.6/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down
1 change: 1 addition & 0 deletions types/node/v18/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down
11 changes: 11 additions & 0 deletions types/node/v18/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ const result2 = Buffer.concat([utf8Buffer, base64Buffer] as readonly Uint8Array[
Buffer.from({} as { [Symbol.toPrimitive](): number });
}

// ArrayLike or string
{
const arrayOrString = "foo" as number[] | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(arrayOrString);

const typedArrayOrString = "foo" as Uint8Array<ArrayBuffer> | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(typedArrayOrString);
}

// @ts-expect-error
Buffer.from({});
// @ts-expect-error
Expand Down
1 change: 1 addition & 0 deletions types/node/v18/ts5.6/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down
1 change: 1 addition & 0 deletions types/node/v20/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down
11 changes: 11 additions & 0 deletions types/node/v20/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ const result2 = Buffer.concat([utf8Buffer, base64Buffer] as readonly Uint8Array[
Buffer.from({} as { [Symbol.toPrimitive](): number });
}

// ArrayLike or string
{
const arrayOrString = "foo" as number[] | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(arrayOrString);

const typedArrayOrString = "foo" as Uint8Array<ArrayBuffer> | string;
// $ExpectType Buffer || Buffer<ArrayBuffer>
Buffer.from(typedArrayOrString);
}

// @ts-expect-error
Buffer.from({});
// @ts-expect-error
Expand Down
1 change: 1 addition & 0 deletions types/node/v20/ts5.6/buffer.buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ declare module "buffer" {
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
*/
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer;
/**
* Creates a new Buffer using the passed {data}
* @param values to create a new Buffer
Expand Down