Skip to content

Commit

Permalink
fix(lib.d.ts): fixed buffer parameter type of DataView (#53130)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev authored Apr 11, 2023
1 parent 89a6482 commit af5e8e2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ interface DataView {

interface DataViewConstructor {
readonly prototype: DataView;
new(buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number): DataView;
new(buffer: ArrayBufferLike & { BYTES_PER_ELEMENT?: never }, byteOffset?: number, byteLength?: number): DataView;
}
declare var DataView: DataViewConstructor;

Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/dataViewConstructor.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/cases/compiler/dataViewConstructor.ts(1,14): error TS2345: Argument of type 'Uint8Array' is not assignable to parameter of type 'ArrayBuffer & { BYTES_PER_ELEMENT?: never; }'.
Type 'Uint8Array' is not assignable to type '{ BYTES_PER_ELEMENT?: never; }'.
Types of property 'BYTES_PER_ELEMENT' are incompatible.
Type 'number' is not assignable to type 'never'.


==== tests/cases/compiler/dataViewConstructor.ts (1 errors) ====
new DataView(new Uint8Array(32)); // should error
~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'Uint8Array' is not assignable to parameter of type 'ArrayBuffer & { BYTES_PER_ELEMENT?: never; }'.
!!! error TS2345: Type 'Uint8Array' is not assignable to type '{ BYTES_PER_ELEMENT?: never; }'.
!!! error TS2345: Types of property 'BYTES_PER_ELEMENT' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type 'never'.
5 changes: 5 additions & 0 deletions tests/baselines/reference/dataViewConstructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//// [dataViewConstructor.ts]
new DataView(new Uint8Array(32)); // should error

//// [dataViewConstructor.js]
new DataView(new Uint8Array(32)); // should error
5 changes: 5 additions & 0 deletions tests/baselines/reference/dataViewConstructor.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/compiler/dataViewConstructor.ts ===
new DataView(new Uint8Array(32)); // should error
>DataView : Symbol(DataView, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

8 changes: 8 additions & 0 deletions tests/baselines/reference/dataViewConstructor.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/dataViewConstructor.ts ===
new DataView(new Uint8Array(32)); // should error
>new DataView(new Uint8Array(32)) : DataView
>DataView : DataViewConstructor
>new Uint8Array(32) : Uint8Array
>Uint8Array : Uint8ArrayConstructor
>32 : 32

1 change: 1 addition & 0 deletions tests/cases/compiler/dataViewConstructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new DataView(new Uint8Array(32)); // should error
2 changes: 1 addition & 1 deletion tests/lib/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ interface DataView {
}

interface DataViewConstructor {
new (buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView;
new (buffer: ArrayBuffer & { BYTES_PER_ELEMENT?: never }, byteOffset?: number, byteLength?: number): DataView;
}
declare var DataView: DataViewConstructor;

Expand Down

0 comments on commit af5e8e2

Please sign in to comment.