Skip to content

Bug: Types incompatibility between @types/eslint's Globals and SharedConfig's GlobalsConfig #9780

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

utils

Playground Link

https://www.typescriptlang.org/play/?#code/PTAEAEBcGcFoGMAWBTeBrAUBglgWwA4D2ATpKDMtADbYB2ZAZsYbqAESQCe+l8x2+SLEo16bANw4CJMgG9QdeFQCuAE2QBJAOa0SyAGLYqyUAF9QTFu3Ai6kYPBb4AhpAlZkADyKlQ6hs7KVGQU1HYAdI60DNhaABSKKurausQGRshxbFrYkLGpyGwAlEWSQA

Repro Code

// @ts-check

import tseslint from "typescript-eslint";
import { includeIgnoreFile } from "@eslint/compat";

export default tseslint.config(includeIgnoreFile("gitignore"));

ESLint Config

n/a

tsconfig

{
  "compilerOptions": {
    "allowJs": true,
    "module": "NodeNext",
    "skipLibCheck": true,
    "noEmit": true
  }
}

Expected Result

There should be no type errors.

Actual Result

$ pnpm tsc
eslint.config.js:6:32 - error TS2345: Argument of type 'FlatConfig' is not assignable to parameter of type 'ConfigWithExtends'.
  The types of 'languageOptions.globals' are incompatible between these types.
    Type 'Globals' is not assignable to type 'GlobalsConfig'.
      'string' index signatures are incompatible.
        Type 'GlobalConf' is not assignable to type 'GlobalVariableOption'.
          Type '"readable"' is not assignable to type 'GlobalVariableOption'.

6 export default tseslint.config(includeIgnoreFile("gitignore"));
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in eslint.config.js:6

Additional Info

What's happening is that we don't allow 'readable or 'writeable', while @types/eslint does.

On the typescript-eslint side:

type GlobalVariableOptionBase = 'off' | 'readonly' | 'writable';
type GlobalVariableOption = GlobalVariableOptionBase | boolean;
interface GlobalsConfig {
    [name: string]: GlobalVariableOption;
}

On the @types/eslint side:

type GlobalConf = boolean | "off" | "readable" | "readonly" | "writable" | "writeable";

interface Globals {
    [name: string]: GlobalConf;
}

From https://archive.eslint.org/docs/7.0.0/user-guide/configuring:

For historical reasons, the boolean value false and the string value "readable" are equivalent to "readonly". Similarly, the boolean value true and the string value "writeable" are equivalent to "writable". However, the use of older values is deprecated.

I think this means we'll need to add the two deprecated string literal types?

Originally reported by @romanstetsyk in https://discord.com/channels/1026804805894672454/1270028825857626193/1270028825857626193. Thanks! 🙌

Versions

package version
@eslint/compat 1.1.1
@typescript-eslint/utils 8.0.0
TypeScript 5.5.4
ESLint 9.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy