8000 Docs: add type annotation for `tseslint.config()` usage examples · Issue #10508 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Docs: add type annotation for tseslint.config() usage examples #10508

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
2 tasks done
MonstraG opened this issue Dec 16, 2024 · 6 comments · Fixed by #10513
Closed
2 tasks done

Docs: add type annotation for tseslint.config() usage examples #10508

MonstraG opened this issue Dec 16, 2024 · 6 comments · Fixed by #10513
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. package: typescript-eslint Issues related to the typescript-eslint package

Comments

@MonstraG
Copy link

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

In examples of eslint.config.mjs, add:

// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

+ /** @type {FlatConfig.ConfigArray} */
export default tseslint.config(
  eslint.configs.recommended,
  tseslint.configs.recommended,
);

(or whatever there actually should be)

(or add this as a separate FAQ item or something)

Affected URL(s)

https://typescript-eslint.io/getting-started/

Additional Info

I request this for the following 2 reasons:

  1. My repositories use types as much as possible, and whenever I have to write .mjs files, I always add type there, for typescript to check them also
  2. without appropriate type annotation, typescript reports;
TS2742: The inferred type of config cannot be named without a reference to
.pnpm/@typescript-eslint+utils@8.18.0_eslint@9.17.0_typescript@5.7.2/node_modules/@typescript-eslint/utils/ts-eslint
. This is likely not portable. A type annotation is necessary.

While the error sounds important, I would still be raising this issue even if error was not there.

Additionally, I don't actually know what to write there, and never could I find this information. I searched for jsdoc, type annotations, ConfigArray and portable but was unable to find any issues that would give me even a hint at what should be the correct @type.

@MonstraG MonstraG added documentation Documentation ("docs") that needs adding/updating triage Waiting for team members to take a look labels Dec 16, 2024
@bradzacher
Copy link
Member

Could you please provide a reproduction for the error you're seeing?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Dec 16, 2024
@MonstraG
Copy link
Author
MonstraG commented Dec 16, 2024

Copy link

Uh oh! @MonstraG, the image you shared is missing helpful alt text. Check #10508 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@MonstraG
Copy link
Author

it seeeeeems that for writing:

/** @type {import("typescript-eslint/dist/config-helper").InfiniteDepthConfigWithExtends} */
const a = {
    files: [],
    rules: {},
}

/** @type {import("typescript-eslint/dist/config-helper").InfiniteDepthConfigWithExtends} */
const b = {
    files: [],
    rules: {},
}

export const appConfig = tseslint.config(a, b);

could work, but of course that's from dist and not actually exported and doesn't build.

@bradzacher bradzacher added bug Something isn't working accepting prs Go ahead, send a pull request that resolves this issue package: typescript-eslint Issues related to the typescript-eslint package and removed documentation Documentation ("docs") that needs adding/updating awaiting response Issues waiting for a reply from the OP or another party labels Dec 17, 2024
@bradzacher
Copy link
Member

Your eslint.config.mjs is covered by a tsconfig that has composite: true. This implies declaration: true -- so your config is trying to generate a .d.ts file for a JS config file.

This is a highly unusual setup and not recommended for obvious reasons and is why you're getting the error. TS is trying to generate a .d.ts file and it's not able to name the types because we hadn't exported all of the types from the top-level, and TS does not like inserting imports to packages you haven't imported explicitly.

We can fix this on our side so that it "just works"

@JoshuaKGoldberg
Copy link
Member
JoshuaKGoldberg commented Dec 17, 2024

Wow, what timing! I just hit this on my own monorepo with a composite: true TSConfig used for eslint.config.js type info. +1

https://github.com/JoshuaKGoldberg/create/tree/4814c13a2f27200b6ebda1f377a94708ce520534

@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 Dec 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2024
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. package: typescript-eslint Issues related to the typescript-eslint package
Projects
None yet
3 participants
0