Skip to content

Commit e0943b1

Browse files
committed
TS: declare Uint8Array<ArrayBuffer> over generic Uint8Array (#20)
And add lint TS rule to enforce declaring `Uint8Array<ArrayBuffer>`. This change is to limit the need to downcast Uint8Array in output when using them with e.g. WebCrypto and Blobs, following an incompatible interface change between ArrayBuffer and ArrayBufferLike (enforced in TS v5.9).
1 parent 2099be4 commit e0943b1

File tree

6 files changed

+106
-84
lines changed

6 files changed

+106
-84
lines changed

eslint.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import pluginImport from 'eslint-plugin-import';
99
import pluginStylistic from '@stylistic/eslint-plugin';
1010
import pluginUnicorn from 'eslint-plugin-unicorn';
1111
import pluginJSDoc from 'eslint-plugin-jsdoc';
12+
// @ts-expect-error missing types
13+
import pluginEnforceUint8ArrayArrayBuffer from '@protontech/eslint-plugin-enforce-uint8array-arraybuffer';
1214

1315
export default defineConfig(
1416
eslint.configs.recommended,
@@ -49,7 +51,8 @@ export default defineConfig(
4951
'chai-friendly': pluginChaiFriendly,
5052
'import': pluginImport,
5153
'@stylistic': pluginStylistic,
52-
'unicorn': pluginUnicorn
54+
'unicorn': pluginUnicorn,
55+
'@protontech/enforce-uint8array-arraybuffer': pluginEnforceUint8ArrayArrayBuffer
5356
},
5457
rules: {
5558
'arrow-body-style': 'off',
@@ -155,6 +158,7 @@ export default defineConfig(
155158
'@typescript-eslint/restrict-template-expressions': 'off',
156159
'prefer-promise-reject-errors': 'off',
157160
'@typescript-eslint/prefer-promise-reject-errors': 'off',
161+
'@protontech/enforce-uint8array-arraybuffer/enforce-uint8array-arraybuffer': 'error',
158162

159163
'@stylistic/indent': ['error', 2, { 'SwitchCase': 1 }],
160164
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],

0 commit comments

Comments
 (0)