Skip to content

[bug]: Typescript Build Issue with noUncheckedIndexedAccess #3976

@bhb603

Description

@bhb603

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions