sqlmancer icon indicating copy to clipboard operation
sqlmancer copied to clipboard

Issue when using esModuleInterop option

Open tsiege opened this issue 4 years ago • 3 comments

I'm running into an issue with the orderBy statement on a query. Fairly certain this is a bug with the type definitions since the code works correctly and is cribbed from the examples. I've looked for an enum to no avail, but I don't think I should need it since the definition uses a Union type called OrderByDirection.

The following code results in this error

        return client.models.Post.findMany()
          .orderBy([{ publishedAt: 'DESC' }])
          .resolveInfo(info)
          .execute()
Type 'string' is not assignable to type '("ASC" & { [x: string]: "ASC" | "DESC" | undefined; }) | ("ASC" & { sum?: { [x: string]: "ASC" | "DESC" | undefined; } | undefined; avg?: { [x: string]: "ASC" | "DESC" | undefined; } | undefined; min?: { ...; } | undefined; max?: { ...; } | undefined; } & { ...; }) | ("DESC" & { ...; }) | ("DESC" & ... 1 more ... & ...'.

tsiege avatar Jun 16 '20 16:06 tsiege

@TSiege Thanks for the bug report. This does appear to be an issue with the type definitions, but I'm not able to reproduce it on my end. Do you think you could put together a gist or repo with the code needed to reproduce it?

danielrearden avatar Jun 16 '20 19:06 danielrearden

@danielrearden I was able to scope it down to an issue with my tsconfig. Having "esModuleInterop": true, causes the issue, which is surprising since your target output for sqlMancer is commonjs. I wonder if it might be an issue with typescript. I'm on TS version^3.9.5

Here's my tsconfig. If that's not enough I can share a dummy repo

{
  "compilerOptions": {
    "rootDir": ".",
    "outDir": "build",
    "removeComments": true,
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "allowJs": true,
    "importHelpers": true,
    "alwaysStrict": true,
    "sourceMap": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitAny": false,
    "noImplicitThis": false,
    "strictNullChecks": false
  },
  "include": [
    "migrations/**/*",
    "scripts/**/*",
    "src/**/*",
  ]
}

tsiege avatar Jun 16 '20 20:06 tsiege

Thanks, that's super helpful. I'll investigate what can be done on this side to prevent those sort of errors.

danielrearden avatar Jun 16 '20 20:06 danielrearden