Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using casualdb with JavaScript yields compiler errors #9

Open
MindfulMinun opened this issue Jul 1, 2020 · 0 comments
Open

Using casualdb with JavaScript yields compiler errors #9

MindfulMinun opened this issue Jul 1, 2020 · 0 comments

Comments

@MindfulMinun
Copy link

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.

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

No branches or pull requests

1 participant