denodrivers / postgres

PostgreSQL driver for Deno

Home Page:https://denodrivers.github.io/postgres

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

strictNullChecks on tsconfig.json breaks module

darklight9811 opened this issue · comments

I know that the error message doesn't have anything to do with what I'm changing on tsconfig, but it happens nonetheless.

tsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "strictNullChecks": false
    }
}

error message

error: TS2345 [ERROR]: Argument of type 'string | T' is not assignable to parameter of type 'T | ArrayResult<T>'.
  Type 'string' is not assignable to type 'T | ArrayResult<T>'.
      this.entries.push(entry);
                        ~~~~~
    at https://deno.land/x/postgres@v0.7.0/query/array_parser.ts:62:25
error Command failed with exit code 1.

This is upstream. You're not supposed to change that, Please read:
https://github.com/denoland/deno/blob/8bef29fd74f24e3682069a1188386d90805a9904/docs/typescript/configuration.md#how-deno-uses-a-configuration-file

image

While it is true that you can have your own tsconfig, since 1.5 Deno has been fighting for an unified environment where all packages have the same tsconfig which creates the assumptions that as long as packages follow Deno directives everything will work.

For more discussion about this, you can read where Deno's core team is leading here:
denoland/deno#7732

@andreespirela , but how would that go? I need to change that because of a package I'm using, and everything works fine until I import this module.

@darklight9811 There's no solution for it, your packages and your code is either Deno standard or it isn't. Packages that are well maintained tend to be Deno standard, so if a package of yours require strictNullChecks is probably outdated.

Cc @Soremwar

@andreespirela, all of this because typescript is being annoying... Do you have any other solution to this?

class Model {
    public constructor (fields: Record<string, unknown>) {
        Object.keys(fields).forEach(key => {
            this[key] = fields[key];
        });
    }
}

class User extends Model {
    public id: string;
    public name: string;
    public email: string;
}

It complains that id, name, and email are not set on constructor.

@darklight9811

you could do

class User extends Model {
      //@ts-ignore
      public id: string
}

and so on
//@ts-ignore directive on top of the fields generating error could save you the pain

@andreespirela, but those fields will be created by the users, I only do the base model. And making them do that seems wrong. I actually feel this whole behaviour of requing initialization wrong. But I could also do public id!: string;

I will find a way, anyway, thanks for the attention.

@andreespirela, by the way. This is the repo I'm talking about:
https://github.com/AcaiFramework/model