Skip to content

Bug: tseslint.config hides user-friendly error messages from ESLint #10549

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

Closed
4 tasks done
abrahamguo opened this issue Dec 26, 2024 · 3 comments · Fixed by #11070
Closed
4 tasks done

Bug: tseslint.config hides user-friendly error messages from ESLint #10549

abrahamguo opened this issue Dec 26, 2024 · 3 comments · Fixed by #11070
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Comments

@abrahamguo
Copy link
Contributor

abrahamguo commented Dec 26, 2024

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.

Issue Description

According to the docs, tseslint.config is a helper function that

  1. gives you the ability to type-check your ESLint config, if you so desire, and
  2. adds support for the extends property on config objects.
    Besides that, it should have no other effect.

However, another "hidden" difference, when using tseslint.config, is that it suppresses user-friendly error messages from ESLint.

For example, if a config object is undefined, ESLint returns:
TypeError: Config (unnamed): Unexpected undefined config at user-defined index 0.

but tseslint.config returns:
TypeError: Cannot destructure property 'extends' of 'configWithExtends' as it is undefined.
which is a less-helpful error.

Now, in an ideal world, TypeScript would report that a user had passed undefined to the function. However, I think there are several things to consider:

  • Users may choose to keep their eslint.config.js in JavaScript, and not type-check it, while still using tseslint.config()
  • Users may misspell a preset of an ESLint plugin, and that ESLint plugin might not provide TS type definitions, e.g. tseslint.config(eslintPlugin['nonexistent-preset']);
  • No matter what happens on the TypeScript side, tseslint.config should not remove any functionality on the JavaScript side, since that's what the docs say.

Reproduction Repository Link

https://github.com/abrahamguo/repro/tree/undefined-config

Repro Steps

  1. clone the repo
  2. npm i
  3. npx eslint -c tseslint.config.js . — compare with npx eslint .

Versions

package version
typescript-eslint 8.18.2
ESLint 9.17.0
@abrahamguo abrahamguo added bug Something isn't working triage Waiting for team members to take a look labels Dec 26, 2024
@abrahamguo abrahamguo changed the title Bug: tseslint.config hides user-friendly error messages from ESLint Bug: tseslint.config hides user-friendly error messages from ESLint Dec 26, 2024
@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Dec 27, 2024

+1 to handling this better.

To be clear, currently tseslint.config(undefined) is a TS error, assuming you have a tsconfig set up to check the lint conifg, and you have strict null checks enabled. But I agree with your points that we can't really assume this, and, even then, types may not match their runtime values for a variety of reasons (especially being undefined instead of a real object).

IMO it would make sense for the signature of tseslint.config() to demand proper TS types, but for the implementation to make no assumptions at all about the runtime values that it receives, and just forward them along unchanged, unless they're an array (which we flatten) or an object with an extends property (which we replace with multiple objects). The issue here is that the implementation assumes, without validating, that a value must be either an array or an object, so it fails when accessing the extends property of undefined.

@abrahamguo
Copy link
Contributor Author

Completely agree!

@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Dec 29, 2024
@kirkwaiblinger
Copy link
Member

Marked accepting PRs 👍

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 29, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
Projects
None yet
2 participants
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