Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Log event typing breaks when adding datasources to PrismaClient constructor #801

Closed
ianwensink opened this issue Jul 23, 2020 · 1 comment · Fixed by prisma/prisma#3428
Closed
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.
Milestone

Comments

@ianwensink
Copy link

Bug description

When creating the PrismaClient, you can pass a log array with an entry to emit query events. By doing so, you can later on use prisma.on('query', callback);. Without the log property during initialisation, the event won't work, since the typing looks at keyof PrismaClientOptions extends 'log'.

When I add another property to the options object (e.g. datasources), this typing breaks. It will throw a Argument of type '"query"' is not assignable to parameter of type 'never'.ts(2345) error. My assumption would be that keyof PrismaClientOptions no longer only extends 'log', but now also has a key called 'datasources'.

Am I doing something wrong, or should this just work?

How to reproduce

The following will work fine and as expected.

const prisma = new PrismaClient({
  log: [
    {
      emit: 'event',
      level: 'query',
    },
  ],
});

prisma.on('query', (e) => {
  console.log(e);
});

But this will break the typing of the event listener:

const prisma = new PrismaClient({
  datasources: {
    db: {
      url: '[INSERT_POSTGRES_CONNECTION_STRING]',
    },
  },
  log: [
    {
      emit: 'event',
      level: 'query',
    },
  ],
});

prisma.on('query', (e) => {
  console.log(e);
});

Expected behavior

I'd expect that adding other properties to the options object, doesn't break the typings for event listeners.

@divyenduz divyenduz added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. process/candidate Candidate for next Milestone. tech/typescript Issue for tech TypeScript. labels Jul 27, 2020
@divyenduz
Copy link

I am able to reproduce this https://www.loom.com/share/7b8386a150c04ed09c24110069bc0164

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants