Joshlha / reified-client-api

Typescript wrapper API for ZAFClient
https://www.npmjs.com/package/reified-client-api
MIT License
7 stars 1 forks source link

unable to use Support.Common.Objects.currentUser.custom_field with webpack #6

Open bkw opened 3 months ago

bkw commented 3 months ago

While trying to come up with an answer for @rajeshpatil-mset in https://github.com/Joshlha/reified-client-api/pull/5#issuecomment-2047696339, I noticed something curious:

This code:

await client.set(
  Support.Common.Objects.currentUser.custom_field!<string>("loyalty_ids"),
  "Hello, world!"
)

... satisfies both eslint as well as tsc, but bundled with webpack in nextJs 14, the browser throws the following error:

Uncaught TypeError: reified_client_api__WEBPACK_IMPORTED_MODULE_2__.Support.Common.Objects.currentUser.custom_field is not a function

Maybe some overzealous optimisation (tree shaking?) is removing the function from the compiled code. I'm aware that this may very well be a local configuration error - I'm using nextjs and am not an expert on all the webpack optimisations they have going on that may be involved with this. But I figured I'd mention this anyway, you may have a better idea if there is anything we can to do avoid this.

FWIW, as a workaround, the following has worked fine, but somewhat defeats the purpose of this library:

await client.set(
  { _path: "currentUser.customField:loyalty_ids", _writeType: "" },
  "Hello, other world!"
)
rajeshpatil-mset commented 3 months ago

@bkw its working for me. cool