casualdb icon indicating copy to clipboard operation
casualdb copied to clipboard

Using casualdb with JavaScript yields compiler errors

Open MindfulMinun opened this issue 4 years ago • 0 comments

Hi, I wanted to use casualdb in Deno with JavaScript instead of TypeScript, but it was giving me compiler errors.

Here's my JavaScript code:

import { CasualDB } from "https://deno.land/x/[email protected]/mod.ts";

// interface Schema {
//     data: any
// }

const db = new CasualDB()

await db.connect('./db.json')

And here are the errors I'm getting:

error: TS2345 [ERROR]: Argument of type 'Object' is not assignable to parameter of type 'Schema'.
  'Schema' could be instantiated with an arbitrary type which could be unrelated to 'Object'.
    The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
    return this._connector.write(updatedData);
                                 ~~~~~~~~~~~
    at https://deno.land/x/[email protected]/mod.ts:32:34

TS2769 [ERROR]: No overload matches this call.
  Overload 1 of 2, '(callbackfn: (value: Op, index: number, array: Op[]) => value is Op, thisArg?: any): Op[]', gave the following error.
    Argument of type 'Function' is not assignable to parameter of type '(value: Op, index: number, array: Op[]) => value is Op'.
      Type 'Function' provides no match for the signature '(value: Op, index: number, array: Op[]): value is Op'.
  Overload 2 of 2, '(callbackfn: (value: Op, index: number, array: Op[]) => unknown, thisArg?: any): Op[]', gave the following error.
    Argument of type 'Function' is not assignable to parameter of type '(value: Op, index: number, array: Op[]) => unknown'.
      Type 'Function' provides no match for the signature '(value: Op, index: number, array: Op[]): unknown'.
    const filtered = this.data.filter(predicateFunction);
                                      ~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/operator/collection.ts:52:39

TS2345 [ERROR]: Argument of type 'U[]' is not assignable to parameter of type '(string | string[])[]'.
  Type 'U' is not assignable to type 'string | string[]'.
    Type 'keyof Op' is not assignable to type 'string | string[]'.
      Type 'string | number | symbol' is not assignable to type 'string | string[]'.
        Type 'number' is not assignable to type 'string | string[]'.
          Type 'keyof Op' is not assignable to type 'string[]'.
            Type 'U' is not assignable to type 'string[]'.
              Type 'keyof Op' is not assignable to type 'string[]'.
                Type 'string | number | symbol' is not assignable to type 'string[]'.
                  Type 'string' is not assignable to type 'string[]'.
    const picked = pick(this.data, ...paths) as { [P in U]: Op[P] };
                                   ~~~~~~~~
    at https://deno.land/x/[email protected]/operator/primitive.ts:24:36

Found 3 errors.

Porting the code to TypeScript doesn't throw any errors and works fine, creating the db.json file with an empty object as expected.

import { CasualDB } from "https://deno.land/x/[email protected]/mod.ts";

interface Schema {
    data: any
}

const db = new CasualDB<Schema>()

await db.connect('./db.json')

I suspected it might be because of the missing type argument, but removing it from the TypeScript example didn't throw any errors, it worked just the same.

MindfulMinun avatar Jul 01 '20 07:07 MindfulMinun