Skip to content

Commit 8ae98d0

Browse files
authored
Fix to use string literal type in ArrayBuffer's Symbol.toStringTag (#60150)
1 parent 244303f commit 8ae98d0

7 files changed

+46
-3
lines changed

src/harness/vfsUtil.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ export class FileSystem {
637637
*
638638
* NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module.
639639
*/
640-
public readFileSync(path: string, encoding?: null): Buffer; // eslint-disable-line no-restricted-syntax
640+
public readFileSync(path: string, encoding?: null): Buffer<ArrayBuffer>; // eslint-disable-line no-restricted-syntax
641641
/**
642642
* Read from a file.
643643
*
@@ -649,7 +649,7 @@ export class FileSystem {
649649
*
650650
* NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module.
651651
*/
652-
public readFileSync(path: string, encoding?: BufferEncoding | null): string | Buffer; // eslint-disable-line no-restricted-syntax
652+
public readFileSync(path: string, encoding?: BufferEncoding | null): string | Buffer<ArrayBuffer>; // eslint-disable-line no-restricted-syntax
653653
public readFileSync(path: string, encoding: BufferEncoding | null = null) { // eslint-disable-line no-restricted-syntax
654654
const { node } = this._walk(this._resolve(path));
655655
if (!node) throw createIOError("ENOENT");

src/lib/es2015.symbol.wellknown.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ interface String {
251251
}
252252

253253
interface ArrayBuffer {
254-
readonly [Symbol.toStringTag]: string;
254+
readonly [Symbol.toStringTag]: "ArrayBuffer";
255255
}
256256

257257
interface DataView<TArrayBuffer extends ArrayBufferLike> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
assignSharedArrayBufferToArrayBuffer.ts(1,5): error TS2322: Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
2+
Types of property '[Symbol.toStringTag]' are incompatible.
3+
Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
4+
5+
6+
==== assignSharedArrayBufferToArrayBuffer.ts (1 errors) ====
7+
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
8+
~~~
9+
!!! error TS2322: Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
10+
!!! error TS2322: Types of property '[Symbol.toStringTag]' are incompatible.
11+
!!! error TS2322: Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
2+
3+
//// [assignSharedArrayBufferToArrayBuffer.ts]
4+
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
5+
6+
//// [assignSharedArrayBufferToArrayBuffer.js]
7+
var foo = new SharedArrayBuffer(1024); // should error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
2+
3+
=== assignSharedArrayBufferToArrayBuffer.ts ===
4+
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
5+
>foo : Symbol(foo, Decl(assignSharedArrayBufferToArrayBuffer.ts, 0, 3))
6+
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
7+
>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --))
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
2+
3+
=== assignSharedArrayBufferToArrayBuffer.ts ===
4+
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
5+
>foo : ArrayBuffer
6+
> : ^^^^^^^^^^^
7+
>new SharedArrayBuffer(1024) : SharedArrayBuffer
8+
> : ^^^^^^^^^^^^^^^^^
9+
>SharedArrayBuffer : SharedArrayBufferConstructor
10+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
>1024 : 1024
12+
> : ^^^^
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: es5
2+
// @lib: es2015,es2017.sharedmemory
3+
4+
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error

0 commit comments

Comments
 (0)