algoliasearch-client-javascript
algoliasearch-client-javascript copied to clipboard
ReadOnly in types
Hi,
I started using the v4 and had some type issues with the transporter
:
https://github.com/algolia/algoliasearch-client-javascript/blob/97dbe4e5f4259d26670c6abb3527aa276f59513f/packages/transporter/src/types/Transporter.ts#L78-L93
read
and write
return a ReadOnly<Promise<TResponse>>
which is a nice intent but makes it incompatible with function or whatever else that expects a Promise<TResponse>
. How would you feel about removing the ReadOnly
, which may make slightly less type safe but much more compatible with other libraries/custom code?
What if instead TResponse would be the readonly, I think that could help
What if instead TResponse would be the readonly, I think that could help
That seem to work in my specific use case but I'm not sure it wouldn't create type issues in some cases. Plus, do you really want to prevent the consumer from applying write operations on the Payload?
Plus, do you really want to prevent the consumer from applying write operations on the Payload?
No. And since v4.2.0, all the responses are now writable: https://github.com/algolia/algoliasearch-client-javascript/pull/1068.
read and write return a ReadOnly<Promise<TResponse>> which is a nice intent but makes it incompatible with function or whatever else that expects a Promise<TResponse>.
I need to think about this a little bit,
I'm currently upgrading from 3.35.1
to 4.3.0
- I used to do this
await usersIndex.addObject({ ... });
after changing to
await usersIndex.saveObject({ ... });
I'm getting the a Typescript warning saying Invalid 'await' of a non-Promise value. (await-promise)
.
~Also im not too sure when addObject
changed to saveObject
but it wasn't in the migration guide~
@malimccalla I wasnt so sure if the strikethrough was because you found in migration guide, but it is here
Malim had the right link at the time, but I updated it to add addObject -> saveObject migration (it was mentioned somewhere else, but not in the real migration guide for some reason) :)