elysiajs / elysia-static

Plugin for Elysia for serving static folder
MIT License
12 stars 17 forks source link

turn on noUncheckedIndexedAccess rule in tsconfig #8

Closed danadajian closed 1 year ago

danadajian commented 1 year ago

When setting noUncheckedIndexedAccess to true in a project consuming this library, type errors ensue:

node_modules/@elysiajs/static/src/index.ts:107:34 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

107                 if (shouldIgnore(file)) continue
                                     ~~~~

node_modules/@elysiajs/static/src/index.ts:109:62 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(path: string | URL, options?: BlobPropertyBag | undefined): BunFile', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'string | URL'.
      Type 'undefined' is not assignable to type 'string | URL'.
  Overload 2 of 3, '(path: Uint8Array | ArrayBufferLike, options?: BlobPropertyBag | undefined): BunFile', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'Uint8Array | ArrayBufferLike'.
      Type 'undefined' is not assignable to type 'Uint8Array | ArrayBufferLike'.
  Overload 3 of 3, '(fileDescriptor: number, options?: BlobPropertyBag | undefined): BunFile', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'number'.
      Type 'undefined' is not assignable to type 'number'.

109                 const response = () => new Response(Bun.file(file))
                                                                 ~~~~

node_modules/@elysiajs/static/src/index.ts:110:32 - error TS18048: 'file' is possibly 'undefined'.

110                 let fileName = file
                                   ~~~~
SaltyAom commented 1 year ago

Fixed with 0.7.1 https://github.com/elysiajs/elysia-static/commit/403223119bdc52910c75044b7cf5ebf4bda01699

Let me know if the problem still persists