Skip to content

npm install fails: TypeScript errors due to ESLint Linter.Config languageOptions index-signature typing (TS4111/TS2698/TS18046) #853

@apple-yagi

Description

@apple-yagi

What happened

Running npm install fails because prepare runs npm run build && husky, and tsc errors out.

Steps to reproduce

  1. Clone this repo
  2. npm install

Actual result

lib/config.ts:56:57 - error TS4111: Property 'ecmaVersion' comes from an index signature, so it must be accessed with ['ecmaVersion'].

56    ecmaVersion: configXoTypescript[0]?.languageOptions?.ecmaVersion,
                                                           ~~~~~~~~~~~

lib/config.ts:57:56 - error TS4111: Property 'sourceType' comes from an index signature, so it must be accessed with ['sourceType'].

57    sourceType: configXoTypescript[0]?.languageOptions?.sourceType,
                                                          ~~~~~~~~~~

lib/config.ts:59:5 - error TS2698: Spread types may only be created from object types.

59     ...configXoTypescript[0]?.languageOptions?.parserOptions,
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/config.ts:59:48 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

59     ...configXoTypescript[0]?.languageOptions?.parserOptions,
                                                  ~~~~~~~~~~~~~

lib/config.ts:384:5 - error TS2698: Spread types may only be created from object types.

384     ...configXoTypescript[4]?.languageOptions?.parserOptions,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/config.ts:384:48 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

384     ...configXoTypescript[4]?.languageOptions?.parserOptions,
                                                   ~~~~~~~~~~~~~

lib/utils.ts:92:32 - error TS4111: Property 'parser' comes from an index signature, so it must be accessed with ['parser'].

92    && !config.languageOptions?.parser
                                  ~~~~~~

lib/utils.ts:93:8 - error TS7053: Element implicitly has an 'any' type because expression of type '"project"' can't be used to index type '{}'.
  Property 'project' does not exist on type '{}'.

93    && !config.languageOptions?.parserOptions?.['project']
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/utils.ts:93:32 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

93    && !config.languageOptions?.parserOptions?.['project']
                                  ~~~~~~~~~~~~~

lib/utils.ts:132:29 - error TS4111: Property 'parser' comes from an index signature, so it must be accessed with ['parser'].

132      config.languageOptions.parser = configXoTypescript[1]?.languageOptions?.parser;
                                ~~~~~~

lib/utils.ts:132:78 - error TS4111: Property 'parser' comes from an index signature, so it must be accessed with ['parser'].

132      config.languageOptions.parser = configXoTypescript[1]?.languageOptions?.parser;
                                                                                 ~~~~~~

lib/utils.ts:142:4 - error TS7053: Element implicitly has an 'any' type because expression of type '"project"' can't be used to index type '{}'.
  Property 'project' does not exist on type '{}'.

142    config.languageOptions?.parserOptions?.['project'] !== undefined
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/utils.ts:142:28 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

142    config.languageOptions?.parserOptions?.['project'] !== undefined
                               ~~~~~~~~~~~~~

lib/utils.ts:143:7 - error TS7053: Element implicitly has an 'any' type because expression of type '"projectService"' can't be used to index type '{}'.
  Property 'projectService' does not exist on type '{}'.

143    || config.languageOptions?.parserOptions?.['projectService'] !== undefined
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/utils.ts:143:31 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

143    || config.languageOptions?.parserOptions?.['projectService'] !== undefined
                                  ~~~~~~~~~~~~~

lib/utils.ts:144:7 - error TS7053: Element implicitly has an 'any' type because expression of type '"tsconfigRootDir"' can't be used to index type '{}'.
  Property 'tsconfigRootDir' does not exist on type '{}'.

144    || config.languageOptions?.parserOptions?.['tsconfigRootDir'] !== undefined
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/utils.ts:144:31 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

144    || config.languageOptions?.parserOptions?.['tsconfigRootDir'] !== undefined
                                  ~~~~~~~~~~~~~

lib/xo.ts:287:26 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

287   config.languageOptions.parserOptions ??= {};
                             ~~~~~~~~~~~~~

lib/xo.ts:288:3 - error TS18046: 'config.languageOptions.parserOptions' is of type 'unknown'.

288   config.languageOptions.parserOptions['projectService'] = false;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/xo.ts:288:26 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

288   config.languageOptions.parserOptions['projectService'] = false;
                             ~~~~~~~~~~~~~

lib/xo.ts:289:3 - error TS18046: 'config.languageOptions.parserOptions' is of type 'unknown'.

289   config.languageOptions.parserOptions['project'] = fallbackTsConfigPath;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/xo.ts:289:26 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

289   config.languageOptions.parserOptions['project'] = fallbackTsConfigPath;
                             ~~~~~~~~~~~~~

lib/xo.ts:290:3 - error TS18046: 'config.languageOptions.parserOptions' is of type 'unknown'.

290   config.languageOptions.parserOptions['tsconfigRootDir'] = this.linterOptions.cwd;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/xo.ts:290:26 - error TS4111: Property 'parserOptions' comes from an index signature, so it must be accessed with ['parserOptions'].

290   config.languageOptions.parserOptions['tsconfigRootDir'] = this.linterOptions.cwd;
                             ~~~~~~~~~~~~~

test/xo/files-matching.test.ts:494:5 - error TS2578: Unused '@ts-expect-error' directive.

494     // @ts-expect-error - This is a test, parserOptions.project just needs to be set
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 25 errors in 4 files.

Errors  Files
     6  lib/config.ts:56
    11  lib/utils.ts:92
     7  lib/xo.ts:287
     1  test/xo/files-matching.test.ts:494

Expected result

npm install completes successfully.

Notes / suspicion

Looks like eslint’s Linter.Config.languageOptions is typed via an index signature (or unknown)
in the current ESLint type definitions, and @sindresorhus/tsconfig enables
noPropertyAccessFromIndexSignature, so dot access/spread is now rejected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions