Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Problem

Recent CI runs were failing with TypeScript 5.9.3 type errors:

Error: index.js(57,58): error TS2345: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'BufferSource'.
Error: index.js(259,25): error TS2345: Argument of type 'Uint8Array<ArrayBuffer>' is not assignable to parameter of type 'ArrayBuffer'.

TypeScript 5.9.3 introduced stricter type checking for buffer types, specifically distinguishing between ArrayBuffer and ArrayBufferLike (which includes SharedArrayBuffer). The Web Crypto API methods require precise buffer types for security reasons.

Solution

Updated JSDoc type annotations to be more precise and compatible with the stricter type system:

  1. Changed secret parameter types from ArrayBuffer to BufferSource in generateHOTP and verifyHOTP functions

    • BufferSource is the correct type for Web Crypto API, accepting both ArrayBuffer and ArrayBufferView types
    • This aligns with the actual API requirements and provides better type safety
  2. Made intToBytes return type explicit as Uint8Array<ArrayBuffer>

    • Ensures TypeScript understands we're returning a Uint8Array backed by an ArrayBuffer, not a SharedArrayBuffer
    • Prevents type widening to Uint8Array<ArrayBufferLike>
  3. Removed unnecessary Uint8Array wrapper in verifyTOTP

    • base32Decode already returns an ArrayBuffer which is now compatible with the updated BufferSource type
    • Eliminates an unnecessary object creation

Verification

  • ✅ All TypeScript type errors resolved
  • ✅ All tests pass (15/15) with 100% coverage
  • ✅ Type declarations generate successfully
  • ✅ No runtime behavior changes

These changes are purely type annotations and don't affect the runtime behavior of the code.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix CI</issue_title>
<issue_description>In a recent CI run we got the following error output:

3s
Run npx -p typescript tsc --declaration --emitDeclarationOnly --allowJs --checkJs --skipLibCheck --downlevelIteration --module nodenext --moduleResolution nodenext --target es2022 --outDir . index.js
npm warn exec The following package was not found and will be installed: typescript@5.9.3
Error: index.js(57,58): error TS2345: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'BufferSource'.
  Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'ArrayBufferView<ArrayBuffer>'.
    Types of property 'buffer' are incompatible.
      Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
        Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
          Types of property '[Symbol.toStringTag]' are incompatible.
            Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
Error: index.js(259,25): error TS2345: Argument of type 'Uint8Array<ArrayBuffer>' is not assignable to parameter of type 'ArrayBuffer'.
  Types of property '[Symbol.toStringTag]' are incompatible.
    Type '"Uint8Array"' is not assignable to type '"ArrayBuffer"'.
Error: Process completed with exit code 2.

Please investigate this issue and fix it.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #29


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Note

Corrects JSDoc types for HOTP functions and removes unnecessary Uint8Array wrapping in TOTP verification.

  • Type fixes:
    • Update generateHOTP and verifyHOTP secret JSDoc types from ArrayBuffer to BufferSource.
    • Adjust intToBytes JSDoc return type to Uint8Array<ArrayBuffer>.
  • Behavioral tweak:
    • In verifyTOTP, pass decodedSecret directly to verifyHOTP (remove new Uint8Array(...) wrapper).

Written by Cursor Bugbot for commit fb9840d. This will update automatically on new commits. Configure here.

Co-authored-by: kentcdodds <1500684+kentcdodds@users.noreply.github.com>
@kentcdodds kentcdodds marked this pull request as ready for review October 23, 2025 00:11
Copilot AI changed the title [WIP] Fix CI error in TypeScript compilation Fix TypeScript 5.9.3 type errors in CI Oct 23, 2025
Copilot AI requested a review from kentcdodds October 23, 2025 00:12
Copilot finished work on behalf of kentcdodds October 23, 2025 00:12
@kentcdodds kentcdodds merged commit 968ffe8 into main Oct 23, 2025
6 of 7 checks passed
@kentcdodds kentcdodds deleted the copilot/fix-ci-error-handling branch October 23, 2025 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix CI

2 participants