Is it not advisable to use the spread operator as ...
# orm-help
g
Is it not advisable to use the spread operator as an argument to a
data
param? For example:
Copy code
const store = await this.prisma.store.create({
  include: { accounts: true, shopifyOfflineSession: true },
  data: {
    ...options,
  }
}
I’ve not tested it thoroughly but it feels that types aren’t strictly checked like this.
1
j
Spread operator is 100% statically typed. if you were to try to spread in something that doesn't perfectly satisfy the type it would throw a static compilation error.
Unless, of course, you violate every rule of static typing, then all bets are off:
n
Hey Gezim 👋 As Jacob mentioned, you could definitely use spread operator and I have seen many users doing that. I don’t see any issue.
g
Thanks @Nurul and @Jacob Martin! I guess I got bit by the runtime type changing under my feet 😞
j
You can eliminate all runtime boundaries by doing proper runtime type identification with a tool like
io-ts
😍 1
Define types for all user input, JSON retrieved from third party APIs, etc. etc.
Then you will never get bit by a schema change
g
You can eliminate all runtime boundaries by doing proper runtime type..
Never knew that! Thanks!
@Jacob Martin I found my actual issue and it’s not made up! It’s not clear why line 41 here isn’t erroring: https://dpaste.com/GB3BLLDP5#line-41
Store and ShopifyOfflineStoreSession have a 1-to-1 relationship: https://dpaste.com/59V7W6FUB
@Nurul Any insights on the lack of error?
j
You must be missing some types my guy
g
@Jacob Martin Here’s the issue being discussed outside of prisma: https://stackoverflow.com/questions/59318739/is-there-an-option-to-make-spreading-an-object-strict
Copy code
Property 'b' is missing in type '{ a: string; }' but required in type 'Y'.
Spread is 100% statically typed
The answer guy is correct, exact types aren't a thing
By design