Skip to content

Fix type checks - #164

Open
Bouni wants to merge 5 commits into
kittendevv:mainfrom
Bouni:fix-type-checks
Open

Bouni wants to merge 5 commits into
kittendevv:mainfrom
Bouni:fix-type-checks

Conversation

@Bouni

@Bouni Bouni commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fix backend type check errors

Running deno check src/ in backend/ reported 9 errors on main. This PR fixes all of them, so the backend type check now passes cleanly.

Behaviour stays the same. The changes are type annotations, one dead file removed, and a clearer error when the database isn't initialized.

Summary

File Error Fix
database/init.ts:741 Type 'undefined' is not assignable to type 'DB' Type db as DB | undefined
database/init.ts:775–832 (×5) 'db' is possibly 'undefined' (follows from the change above) Use getDatabase()
controllers/templates.ts:650 Uint8Array<ArrayBufferLike> not assignable to BlobPart Type zip data as Uint8Array<ArrayBuffer>
utils/oidc.ts:196 Property 'kid' does not exist on type 'JsonWebKey' Read kid through Record<string, unknown>
utils/oidc.ts:216 Uint8Array<ArrayBufferLike> not assignable to BufferSource Return Uint8Array<ArrayBuffer> from b64urlToBytes
controllers/templates_new.ts:23 Property 'templateType' is missing Delete the unused file

Commits

1. Allow db to be undefined after closeDatabase()

closeDatabase() resets the module-level handle to undefined, but db was declared as plain DB. It is now DB | undefined.

That made five direct db.query(...) calls in the invoice-numbering helpers (getNumberingConfig, findMaxSequence, getCustomerNumber) fail the type check. They now go through getDatabase(), like the rest of the codebase. If the database isn't initialized, they now throw Database not initialized. Call initDatabase() first. instead of TypeError: Cannot read properties of undefined (reading 'query'). Callers that wrap these calls in try/catch behave as before.

2. Type template zip data as Uint8Array<ArrayBuffer>

Since TypeScript 5.7, Uint8Array is generic over its buffer type, and a bare Uint8Array (Uint8Array<ArrayBufferLike>) may be backed by a SharedArrayBuffer. new Blob([...]) doesn't accept that. In routes/admin.ts the zip upload is always created with new Uint8Array(arrayBuffer), so the parameter and the local variable are now typed Uint8Array<ArrayBuffer>.

3. Fix OIDC type errors in ID token verification

  • JsonWebKey in the DOM lib doesn't declare kid. It is now read through Record<string, unknown>, which is how the next lines already read use and alg.
  • b64urlToBytes now returns Uint8Array<ArrayBuffer> (which is what Uint8Array.from produces), so the signature is accepted as a BufferSource by crypto.subtle.verify.

4. Remove unused templates_new.ts

This was an old copy of the templates controller. Nothing imports it and it hasn't changed since early development. It no longer matched the Template interface (no templateType), so deleting it was the cleanest fix.

Testing

  • cd backend && deno check src/ → 0 errors
  • OIDC login still works (ID token signature verification)
  • Uploading a local template .zip in Settings still works
  • Creating an invoice still produces the right auto-generated number

🤖 Generated with Claude Code

Bouni and others added 5 commits October 9, 2026 09:28
closeDatabase() resets the module-level handle to undefined, which the
DB type did not permit. Type it as DB | undefined and route the
invoice-numbering helpers through getDatabase() so they get a clear
'Database not initialized' error instead of a TypeError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The zip upload is always built from an ArrayBuffer; stating that lets
it be passed to new Blob() under TypeScript 5.7+ typed arrays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read the JWK 'kid' via Record<string, unknown> like the other non-standard
fields, and return Uint8Array<ArrayBuffer> from b64urlToBytes so the
signature is accepted as a BufferSource by crypto.subtle.verify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Leftover copy of the templates controller that nothing imports; it no
longer matched the Template type and broke the type check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Bouni

Bouni commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I have not tested OIDC due to the lack of an OIDC provider, someone willing to test this is highly appreciated!

@KeplerAeroIT As you implemented this feature you are a hot candidate for testing 😅

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.

1 participant