Fix to use string literal type in ArrayBuffer's Symbol.toStringTag (#60150)

This commit is contained in:
Kenta Moriuchi 2025-02-25 04:17:35 +09:00 committed by GitHub
parent 244303f92f
commit 8ae98d02d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 3 deletions

View File

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

View File

@ -251,7 +251,7 @@ interface String {
}
interface ArrayBuffer {
readonly [Symbol.toStringTag]: string;
readonly [Symbol.toStringTag]: "ArrayBuffer";
}
interface DataView<TArrayBuffer extends ArrayBufferLike> {

View File

@ -0,0 +1,11 @@
assignSharedArrayBufferToArrayBuffer.ts(1,5): error TS2322: Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
Types of property '[Symbol.toStringTag]' are incompatible.
Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
==== assignSharedArrayBufferToArrayBuffer.ts (1 errors) ====
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
~~~
!!! error TS2322: Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
!!! error TS2322: Types of property '[Symbol.toStringTag]' are incompatible.
!!! error TS2322: Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.

View File

@ -0,0 +1,7 @@
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
//// [assignSharedArrayBufferToArrayBuffer.ts]
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
//// [assignSharedArrayBufferToArrayBuffer.js]
var foo = new SharedArrayBuffer(1024); // should error

View File

@ -0,0 +1,8 @@
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
=== assignSharedArrayBufferToArrayBuffer.ts ===
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
>foo : Symbol(foo, Decl(assignSharedArrayBufferToArrayBuffer.ts, 0, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --))

View File

@ -0,0 +1,13 @@
//// [tests/cases/conformance/es2017/assignSharedArrayBufferToArrayBuffer.ts] ////
=== assignSharedArrayBufferToArrayBuffer.ts ===
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error
>foo : ArrayBuffer
> : ^^^^^^^^^^^
>new SharedArrayBuffer(1024) : SharedArrayBuffer
> : ^^^^^^^^^^^^^^^^^
>SharedArrayBuffer : SharedArrayBufferConstructor
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>1024 : 1024
> : ^^^^

View File

@ -0,0 +1,4 @@
// @target: es5
// @lib: es2015,es2017.sharedmemory
var foo: ArrayBuffer = new SharedArrayBuffer(1024); // should error