algoliasearch-client-javascript icon indicating copy to clipboard operation
algoliasearch-client-javascript copied to clipboard

readonly TransporterOptions

Open bodinsamuel opened this issue 5 years ago • 3 comments

hello team,

I played with the client today and while doing so ended up blocked by (another) readonly issue.

I can not conditionnally construct the options because the requester and all of them are readonly

// Pseudo code

const params = {}
if (!params.requester) {
  params.requester = requester;  // => Cannot assign to 'requester' because it is a read-only property.
}

const client = algoliasearch('', '', params);

I am not sure what does the readonly solve in function params, did @nunomaduro documented that decision?

Related #1158

bodinsamuel avatar Sep 16 '20 09:09 bodinsamuel

it's to make sure that the params don't get modified after the client gets created. You can wrap the params in an as const, which should normally solve the issue

Haroenv avatar Sep 16 '20 09:09 Haroenv

putting as const is as good as having not type at all. I would be okay to have the interface of SearchClient readonly but the params themselves it's a bit constraining.

bodinsamuel avatar Sep 16 '20 13:09 bodinsamuel

@bodinsamuel @Haroenv Just stumbled on this issue while integrating search-insights. The README in the search-insights actually encourages us to modify the transporter options: https://github.com/algolia/search-insights.js#access-usertoken.

dardanbujupaj avatar Apr 03 '23 13:04 dardanbujupaj