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

Certain model names cause clashes in generated types #12469

Closed
austincrim opened this issue Mar 21, 2022 · 6 comments · Fixed by #20215
Closed

Certain model names cause clashes in generated types #12469

austincrim opened this issue Mar 21, 2022 · 6 comments · Fixed by #20215
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: prisma-client topic: type-clash
Milestone

Comments

@austincrim
Copy link

austincrim commented Mar 21, 2022

Bug description

The following are all exported types from the index.d.ts and will cause clashes if they have corresponding models in the Prisma schema.

  • PrismaPromise
  • PrismaVersion
  • JsonObject
  • JsonValue
  • InputJsonObject
  • InputJsonValue
  • PromiseType
  • PromiseReturnType
  • Enumerable
  • RequiredKeys
  • TruthyKeys
  • TrueKeys
  • Subset
  • SelectSubset
  • SubsetIntersection
  • UnEnumerate
  • Union
  • IntersectOf
  • Overwrite
  • At
  • ComputeRaw
  • OptionalFlat
  • Strict
  • Merge
  • Boolean
  • True
  • False
  • Not
  • Extends
  • Has
  • Or
  • Keys
  • GetScalarType
  • ModelName
  • Datasources
  • RejectOnNotFound
  • RejectPerModel
  • RejectPerOperation
  • HasReject
  • ErrorFormat
  • Hooks
  • LogLevel
  • LogDefinition
  • GetLogType
  • GetEvents
  • QueryEvent
  • LogEvent
  • PrismaAction
  • MiddlewareParams
  • Middleware
  • Datasource
  • SortOrder
  • QueryMode
  • IntFilter
  • StringFilter
  • IntWithAggregatesFilter
  • StringWithAggregatesFilter
  • StringFieldUpdateOperationsInput
  • IntFieldUpdateOperationsInput
  • NestedIntFilter
  • NestedStringFilter
  • NestedIntWithAggregatesFilter
  • NestedFloatFilter
  • NestedStringWithAggregatesFilter
  • BatchPayload

How to reproduce

  1. Generate a schema with one of the model names listed above
  2. Write Prisma query
  3. Observe return type is incorrect

Expected behavior

No response

Prisma information

n/a

Environment & setup

  • OS: macOS
  • Node.js version: 17.7.1

Prisma Version

3.11

Existing related issues

@austincrim austincrim added the kind/bug A reported bug. label Mar 21, 2022
@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. process/candidate topic: prisma-client topic: client types Types in Prisma Client team/client Issue for team Client. topic: type-clash labels Mar 22, 2022
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Mar 22, 2022
@psikoi
Copy link

psikoi commented Aug 11, 2022

Metric is now also causing conflicts with model names.

@priithaamer
Copy link

Just got hit with this by migrating prisma from 3.x to 4.3 on a project that had a model named Metric.

Renaming the model worked for me but is there another workaround besides that?

@psikoi
Copy link

psikoi commented Sep 6, 2022

Just got hit with this by migrating prisma from 3.x to 4.3 on a project that had a model named Metric.

Renaming the model worked for me but is there another workaround besides that?

If I remember correctly, I had to disable skipLibCheck on tsconfig, but that's not really a great solution :/

@priithaamer
Copy link

If I remember correctly, I had to disable skipLibCheck on tsconfig, but that's not really a great solution :/

Yes, that works as well. But i prefer model rename over this in order not to compromise type safety.

@jove4015
Copy link

jove4015 commented May 4, 2023

@janpio - Just ran into this with our Batch model, which is clobbered by the BatchPayload type (we basically can't validate any Batch items). This is really frustrating because we only just now started to need to control the return type for Batch, and we can't because of the overriding BatchPayload type, but this model is already all over our codebase. Even worse - I read on this issue that the Metric model (which, honestly, we're using a whole lot more and have had already for months) is similarly impacted - and the only reason we haven't noticed is because we already made ourselves a derived type for Metric and don't refer to the Metric model type directly anywhere, purely by accident.

We're going to go through everything and rename both our Batch and Metric models, but - this list here should really, really be in your documentation. It's crazy that it took adding a relationship to a model to discover that we were messing with Prisma internals, and crazier that this is the only place I could find any discussion on the topic. And frankly, Prisma should stop you from generating models if you try to clobber one of these types. It shouldn't even let me create a Metric or a Batch model if this is what's going to happen.

I understand you see this as a "temporary limitation" but it's a real limitation that's going to be with us for the foreseeable future - you have a huge roadmap and I just know this is not at the top of the list. Better to warn people than to pretend it's not there.

SevInf added a commit that referenced this issue Jun 13, 2023
Problem: even though built-in `Metric` type is placed in
a different namespace, type conflict still occurs: `Delegate` classes
are in the same namespace and can't refer to non-namespaced name.

Implements a tiny part of [namespace overhaul proposal](https://www.notion.so/prismaio/Fix-type-name-clashes-in-TS-Client-9e9bbdee13f94a818ece060e55465267): introduces `$Models` namespace.

Ref #12469
SevInf added a commit that referenced this issue Jun 13, 2023
Problem: even though built-in `Metric` type is placed in
a different namespace, type conflict still occurs: `Delegate` classes
are in the same namespace and can't refer to non-namespaced name.

Implements a tiny part of [namespace overhaul proposal](https://www.notion.so/prismaio/Fix-type-name-clashes-in-TS-Client-9e9bbdee13f94a818ece060e55465267): introduces `$Models` namespace.

Ref #12469
SevInf added a commit that referenced this issue Jul 13, 2023
After looking through the issues, we had a couple of more clashes that
needed additional work:

1. `Check` and `Has` collide with built-in `CheckSelect`/`HasSelect`
   types. Those types are not public and not used since prisma 4.16.0,
   so I just removed them from generated file.
2. `Promise` is more complicated and required aliasing built-in type.

Fix #17542
Fix #9669
Close #12469
SevInf added a commit that referenced this issue Jul 18, 2023
…#20215)

* fix(client): Allow to use `Check`, `Has` and `Promise` as model names

After looking through the issues, we had a couple of more clashes that
needed additional work:

1. `Check` and `Has` collide with built-in `CheckSelect`/`HasSelect`
   types. Those types are not public and not used since prisma 4.16.0,
   so I just removed them from generated file.
2. `Promise` is more complicated and required aliasing built-in type.

Fix #17542
Fix #9669
Close #12469

* Ensure type alias is still displayed as `Promise` in editor

* Try different method

---------

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 18, 2023
@SevInf
Copy link
Contributor

SevInf commented Jul 18, 2023

All of those conflicts are fixed and all mentioned names should be useable as model name starting with upcoming Prisma 5.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: prisma-client topic: type-clash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants