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

[bug]: client-common throw types error when noUncheckedIndexedAccess is enable #1561

Closed
RodrigoTomeES opened this issue Oct 14, 2024 · 1 comment · Fixed by algolia/api-clients-automation#3966
Assignees
Labels

Comments

@RodrigoTomeES
Copy link

RodrigoTomeES commented Oct 14, 2024

Description

If you has enable "noUncheckedIndexedAccess": true, in your project you can't compile Next.js projects because the package produce types error.

It can be fixed checking the index.

export function shuffle<TData>(array: TData[]): TData[] {
  const shuffledArray = array;

  for (let c = array.length - 1; c > 0; c--) {
    const b = Math.floor(Math.random() * (c + 1));
    const a = array[c];

    // Added the ifs
    if (array[b]) shuffledArray[c] = array[b];
    if (a) shuffledArray[b] = a;
  }

  return shuffledArray;
}

Client

All

Version

5.8.1

Relevant log output

node_modules/@algolia/client-common/src/transporter/helpers.ts:11:5 - error TS2322: Type 'TData | undefined' is not assignable to type 'TData'.
  'TData' could be instantiated with an arbitrary type which could be unrelated to 'TData | undefined'.

11     shuffledArray[c] = array[b];
       ~~~~~~~~~~~~~~~~

node_modules/@algolia/client-common/src/transporter/helpers.ts:12:5 - error TS2322: Type 'TData | undefined' is not assignable to type 'TData'.
  'TData' could be instantiated with an arbitrary type which could be unrelated to 'TData | undefined'.

12     shuffledArray[b] = a;
       ~~~~~~~~~~~~~~~~

node_modules/@algolia/client-common/src/transporter/helpers.ts:71:5 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

71     serializedHeaders[header.toLowerCase()] = value;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 3 errors in the same file, starting at: node_modules/@algolia/client-common/src/transporter/helpers.ts:11
@shortcuts
Copy link
Member

Hey, thanks for reporting the issue! We shouldn't provide the typescript files in order to prevent those kind of issues, next release will contain the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants