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]: Typescript Build Issue with noUncheckedIndexedAccess #3976

Closed
1 task done
bhb603 opened this issue Oct 15, 2024 · 2 comments
Closed
1 task done

[bug]: Typescript Build Issue with noUncheckedIndexedAccess #3976

bhb603 opened this issue Oct 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bhb603
Copy link

bhb603 commented Oct 15, 2024

Description

I'm trying to enable noUncheckedIndexedAccess in my own TypeScript project's tsconfig, however the @algolia/client-search package throws an error when this config is enabled.

To isolate the issue, I created a fresh project (npm init, npx tsc --init, etc), and imported the @algolia/client-search package. When noUncheckedIndexedAccess is disabled, TypeScript compiles fine. However when enabled, there are errors emitting from the @algolia/client-common package because it does not comply with this stricter TS configuration.

One option would be for Algolia to also use this configuration, which may solve this specific case.

Granted, it feels strange that my own TypeScript config is limited by dependencies, however after reading this thread, and some of the comments and linked issues, it may be the case that Algolia is publishing its modules in a way that depends on ts files (not just d.ts declarations)?

Anyway, this is currently blocking me from enabling the config I want in my own TS projects, and could be a larger issue.

Language

JavaScript

Client

All

Steps to reproduce

  1. create a new nodejs/TypeScript project
  2. add @algolia/client-search as a dependency and import it in one of your modules
  3. enable noUncheckedIndexedAccess in tsconfig
  4. attempt to compile with tsc

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

Self-service

  • I'd be willing to fix this bug myself.
@bhb603 bhb603 added the bug Something isn't working label Oct 15, 2024
@shortcuts
Copy link
Member

Hey, thanks for opening the issue, the fix for this issue has been done in #3966, I'll release later today!

@bhb603
Copy link
Author

bhb603 commented Oct 17, 2024

@shortcuts Thanks for the quick response! I didn't see the issue in the other repo.

Fix looks right, I'll test it out as soon as it's released 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants