Skip to content

Commit 0d2c7b4

Browse files
committed
Revert: microsoft/TypeScript#23155 - Type error in Buffer.from()
1 parent 7f0811a commit 0d2c7b4

File tree

10 files changed

+81
-76
lines changed

10 files changed

+81
-76
lines changed

types/node/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ declare var Buffer: {
219219
*/
220220
new(buffer: Buffer): Buffer;
221221
prototype: Buffer;
222+
/**
223+
* Allocates a new Buffer using an {array} of octets.
224+
*/
225+
from(array: any[]): Buffer;
222226
/**
223227
* When passed a reference to the .buffer property of a TypedArray instance,
224228
* the newly created Buffer will share the same allocated memory as the TypedArray.
@@ -229,10 +233,9 @@ declare var Buffer: {
229233
*/
230234
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
231235
/**
232-
* Creates a new Buffer using the passed {data}
233-
* @param data data to create a new Buffer
236+
* Copies the passed {buffer} data onto a new Buffer instance.
234237
*/
235-
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
238+
from(buffer: Buffer): Buffer;
236239
/**
237240
* Creates a new Buffer containing the given JavaScript string {str}.
238241
* If provided, the {encoding} parameter identifies the character encoding.

types/node/node-tests.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,9 @@ function bufferTests() {
423423
buf.swap64();
424424
}
425425

426-
// Class Method: Buffer.from(data)
426+
// Class Method: Buffer.from(array)
427427
{
428-
// Array
429-
const buf1: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
430-
// Buffer
431-
const buf2: Buffer = Buffer.from(buf1);
432-
// String
433-
const buf3: Buffer = Buffer.from('this is a tést');
434-
// ArrayBuffer
435-
const arr: Uint16Array = new Uint16Array(2);
436-
arr[0] = 5000;
437-
arr[1] = 4000;
438-
const buf4: Buffer = Buffer.from(arr.buffer);
428+
const buf: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
439429
}
440430

441431
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
@@ -445,12 +435,20 @@ function bufferTests() {
445435
arr[1] = 4000;
446436

447437
let buf: Buffer;
438+
buf = Buffer.from(arr.buffer);
448439
buf = Buffer.from(arr.buffer, 1);
449440
buf = Buffer.from(arr.buffer, 0, 1);
450441
}
451442

443+
// Class Method: Buffer.from(buffer)
444+
{
445+
const buf1: Buffer = Buffer.from('buffer');
446+
const buf2: Buffer = Buffer.from(buf1);
447+
}
448+
452449
// Class Method: Buffer.from(str[, encoding])
453450
{
451+
const buf1: Buffer = Buffer.from('this is a tést');
454452
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
455453
}
456454

types/node/v4/index.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ declare var Buffer: {
164164
*/
165165
new (buffer: Buffer): Buffer;
166166
prototype: Buffer;
167+
/**
168+
* Allocates a new Buffer using an {array} of octets.
169+
*/
170+
from(array: any[]): Buffer;
167171
/**
168172
* When passed a reference to the .buffer property of a TypedArray instance,
169173
* the newly created Buffer will share the same allocated memory as the TypedArray.
@@ -172,12 +176,11 @@ declare var Buffer: {
172176
*
173177
* @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()
174178
*/
175-
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?:number): Buffer;
179+
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
176180
/**
177-
* Creates a new Buffer using the passed {data}
178-
* @param data data to create a new Buffer
181+
* Copies the passed {buffer} data onto a new Buffer instance.
179182
*/
180-
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
183+
from(buffer: Buffer): Buffer;
181184
/**
182185
* Creates a new Buffer containing the given JavaScript string {str}.
183186
* If provided, the {encoding} parameter identifies the character encoding.

types/node/v4/node-tests.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,9 @@ function bufferTests() {
240240
var result1 = Buffer.concat([utf8Buffer, base64Buffer]);
241241
var result2 = Buffer.concat([utf8Buffer, base64Buffer], 9999999);
242242

243-
// Class Method: Buffer.from(data)
243+
// Class Method: Buffer.from(array)
244244
{
245-
// Array
246-
const buf1: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
247-
// Buffer
248-
const buf2: Buffer = Buffer.from(buf1);
249-
// String
250-
const buf3: Buffer = Buffer.from('this is a tést');
251-
// ArrayBuffer
252-
const arr: Uint16Array = new Uint16Array(2);
253-
arr[0] = 5000;
254-
arr[1] = 4000;
255-
const buf4: Buffer = Buffer.from(arr.buffer);
245+
const buf: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
256246
}
257247

258248
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
@@ -262,12 +252,20 @@ function bufferTests() {
262252
arr[1] = 4000;
263253

264254
let buf: Buffer;
255+
buf = Buffer.from(arr.buffer);
265256
buf = Buffer.from(arr.buffer, 1);
266257
buf = Buffer.from(arr.buffer, 0, 1);
267258
}
268259

260+
// Class Method: Buffer.from(buffer)
261+
{
262+
const buf1: Buffer = Buffer.from('buffer');
263+
const buf2: Buffer = Buffer.from(buf1);
264+
}
265+
269266
// Class Method: Buffer.from(str[, encoding])
270267
{
268+
const buf1: Buffer = Buffer.from('this is a tést');
271269
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
272270
}
273271

types/node/v6/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ declare var Buffer: {
164164
*/
165165
new (buffer: Buffer): Buffer;
166166
prototype: Buffer;
167+
/**
168+
* Allocates a new Buffer using an {array} of octets.
169+
*/
170+
from(array: any[]): Buffer;
167171
/**
168172
* When passed a reference to the .buffer property of a TypedArray instance,
169173
* the newly created Buffer will share the same allocated memory as the TypedArray.
@@ -174,10 +178,9 @@ declare var Buffer: {
174178
*/
175179
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
176180
/**
177-
* Creates a new Buffer using the passed {data}
178-
* @param data data to create a new Buffer
181+
* Copies the passed {buffer} data onto a new Buffer instance.
179182
*/
180-
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
183+
from(buffer: Buffer): Buffer;
181184
/**
182185
* Creates a new Buffer containing the given JavaScript string {str}.
183186
* If provided, the {encoding} parameter identifies the character encoding.

types/node/v6/node-tests.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,9 @@ function bufferTests() {
321321
buf.swap64();
322322
}
323323

324-
// Class Method: Buffer.from(data)
324+
// Class Method: Buffer.from(array)
325325
{
326-
// Array
327-
const buf1: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
328-
// Buffer
329-
const buf2: Buffer = Buffer.from(buf1);
330-
// String
331-
const buf3: Buffer = Buffer.from('this is a tést');
332-
// ArrayBuffer
333-
const arr: Uint16Array = new Uint16Array(2);
334-
arr[0] = 5000;
335-
arr[1] = 4000;
336-
const buf4: Buffer = Buffer.from(arr.buffer);
326+
const buf: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
337327
}
338328

339329
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
@@ -343,12 +333,20 @@ function bufferTests() {
343333
arr[1] = 4000;
344334

345335
let buf: Buffer;
336+
buf = Buffer.from(arr.buffer);
346337
buf = Buffer.from(arr.buffer, 1);
347338
buf = Buffer.from(arr.buffer, 0, 1);
348339
}
349340

341+
// Class Method: Buffer.from(buffer)
342+
{
343+
const buf1: Buffer = Buffer.from('buffer');
344+
const buf2: Buffer = Buffer.from(buf1);
345+
}
346+
350347
// Class Method: Buffer.from(str[, encoding])
351348
{
349+
const buf1: Buffer = Buffer.from('this is a tést');
352350
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
353351
}
354352

types/node/v7/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ declare var Buffer: {
175175
*/
176176
new (buffer: Buffer): Buffer;
177177
prototype: Buffer;
178+
/**
179+
* Allocates a new Buffer using an {array} of octets.
180+
*/
181+
from(array: any[]): Buffer;
178182
/**
179183
* When passed a reference to the .buffer property of a TypedArray instance,
180184
* the newly created Buffer will share the same allocated memory as the TypedArray.
@@ -185,10 +189,9 @@ declare var Buffer: {
185189
*/
186190
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
187191
/**
188-
* Creates a new Buffer using the passed {data}
189-
* @param data data to create a new Buffer
192+
* Copies the passed {buffer} data onto a new Buffer instance.
190193
*/
191-
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
194+
from(buffer: Buffer): Buffer;
192195
/**
193196
* Creates a new Buffer containing the given JavaScript string {str}.
194197
* If provided, the {encoding} parameter identifies the character encoding.

types/node/v7/node-tests.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,9 @@ function bufferTests() {
303303
buf.swap64();
304304
}
305305

306-
// Class Method: Buffer.from(data)
306+
// Class Method: Buffer.from(array)
307307
{
308-
// Array
309-
const buf1: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
310-
// Buffer
311-
const buf2: Buffer = Buffer.from(buf1);
312-
// String
313-
const buf3: Buffer = Buffer.from('this is a tést');
314-
// ArrayBuffer
315-
const arr: Uint16Array = new Uint16Array(2);
316-
arr[0] = 5000;
317-
arr[1] = 4000;
318-
const buf4: Buffer = Buffer.from(arr.buffer);
308+
const buf: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
319309
}
320310

321311
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
@@ -325,12 +315,20 @@ function bufferTests() {
325315
arr[1] = 4000;
326316

327317
let buf: Buffer;
318+
buf = Buffer.from(arr.buffer);
328319
buf = Buffer.from(arr.buffer, 1);
329320
buf = Buffer.from(arr.buffer, 0, 1);
330321
}
331322

323+
// Class Method: Buffer.from(buffer)
324+
{
325+
const buf1: Buffer = Buffer.from('buffer');
326+
const buf2: Buffer = Buffer.from(buf1);
327+
}
328+
332329
// Class Method: Buffer.from(str[, encoding])
333330
{
331+
const buf1: Buffer = Buffer.from('this is a tést');
334332
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
335333
}
336334

types/node/v8/index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ declare var Buffer: {
217217
*/
218218
new(buffer: Buffer): Buffer;
219219
prototype: Buffer;
220+
/**
221+
* Allocates a new Buffer using an {array} of octets.
222+
*/
223+
from(array: any[]): Buffer;
220224
/**
221225
* When passed a reference to the .buffer property of a TypedArray instance,
222226
* the newly created Buffer will share the same allocated memory as the TypedArray.
@@ -227,10 +231,9 @@ declare var Buffer: {
227231
*/
228232
from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
229233
/**
230-
* Creates a new Buffer using the passed {data}
231-
* @param data data to create a new Buffer
234+
* Copies the passed {buffer} data onto a new Buffer instance.
232235
*/
233-
from(data: any[] | string | Buffer | ArrayBuffer /*| TypedArray*/): Buffer;
236+
from(buffer: Buffer): Buffer;
234237
/**
235238
* Creates a new Buffer containing the given JavaScript string {str}.
236239
* If provided, the {encoding} parameter identifies the character encoding.

types/node/v8/node-tests.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,9 @@ function bufferTests() {
397397
buf.swap64();
398398
}
399399

400-
// Class Method: Buffer.from(data)
400+
// Class Method: Buffer.from(array)
401401
{
402-
// Array
403-
const buf1: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
404-
// Buffer
405-
const buf2: Buffer = Buffer.from(buf1);
406-
// String
407-
const buf3: Buffer = Buffer.from('this is a tést');
408-
// ArrayBuffer
409-
const arr: Uint16Array = new Uint16Array(2);
410-
arr[0] = 5000;
411-
arr[1] = 4000;
412-
const buf4: Buffer = Buffer.from(arr.buffer);
402+
const buf: Buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
413403
}
414404

415405
// Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
@@ -419,12 +409,20 @@ function bufferTests() {
419409
arr[1] = 4000;
420410

421411
let buf: Buffer;
412+
buf = Buffer.from(arr.buffer);
422413
buf = Buffer.from(arr.buffer, 1);
423414
buf = Buffer.from(arr.buffer, 0, 1);
424415
}
425416

417+
// Class Method: Buffer.from(buffer)
418+
{
419+
const buf1: Buffer = Buffer.from('buffer');
420+
const buf2: Buffer = Buffer.from(buf1);
421+
}
422+
426423
// Class Method: Buffer.from(str[, encoding])
427424
{
425+
const buf1: Buffer = Buffer.from('this is a tést');
428426
const buf2: Buffer = Buffer.from('7468697320697320612074c3a97374', 'hex');
429427
}
430428

0 commit comments

Comments
 (0)