Skip to content

fix: add support for exactOptionalPropertyTypes in type definitions #391

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

Conversation

sebastian-altamirano
Copy link

Prerequisites checklist

What is the purpose of this pull request?

When using @eslint/markdown as a plugin in an ESLint config file, TypeScript throws the following error if the exactOptionalPropertyTypes compiler option is enabled:

Type 'typeof plugin' is not assignable to type 'Plugin'.
...
    Type 'undefined' is not assignable to type '(string | string[])[]'.ts(2322)

For example, this can be triggered by using plugins: { markdown } in:

import markdown from "@eslint/markdown";
import { defineConfig } from "eslint/config";

export default defineConfig([
    {
        extends: ["markdown/recommended"],
        files: ["**/*.md"],
        language: "markdown/gfm",
        plugins: { markdown },
        rules: {
            "markdown/no-duplicate-headings": "error",
            "markdown/no-html": "error",
        },
    },
]);

This PR fixes the issue.

What changes did you make? (Give an overview)

I noticed that the Plugin type was unused, so I updated it to be compatible with exactOptionalPropertyTypes and began using it, without breaking existing tests.

Related Issues

-

Is there anything you'd like reviewers to focus on?

-

Copy link

linux-foundation-easycla bot commented May 24, 2025

CLA Signed

  • ✅login: sebastian-altamirano / (9674f9f)

The committers listed above are authorized under a signed CLA.

@sebastian-altamirano sebastian-altamirano changed the title feat: add exactOptionalPropertyTypes to type tests fix: add support for exactOptionalPropertyTypes in type definitions May 24, 2025
@sebastian-altamirano sebastian-altamirano force-pushed the add-exact-optional-property-types branch from 8158703 to 9674f9f Compare May 24, 2025 00:47
@lumirlumir lumirlumir added the repro:needed This issue should include a reproducible example label May 26, 2025
@lumirlumir
Copy link
Member

Hello @sebastian-altamirano, thanks for opening a PR.

Could you provide a reproducible link and your TypeScript tsconfig.json settings? I tried to reproduce the issue, but couldn’t reproduce it on my end.

@sebastian-altamirano
Copy link
Author

Sure, I can't create a reproducible link right now, I'll do it later if you still need it, but I can pass you the tsconfig.json I used to reproduce the problem:

{
	"extends": "@tsconfig/strictest/tsconfig.json",
	"compileOnSave": false,
	"compilerOptions": {
		"baseUrl": "./",
		"outDir": "./dist/out-tsc",
		"strict": true,
		"skipLibCheck": true,
		"isolatedModules": true,
		"esModuleInterop": true,
		"experimentalDecorators": true,
		"moduleResolution": "bundler",
		"importHelpers": true,
		"target": "ES2022",
		"module": "ES2022",
		"paths": {
			"@core/*": ["src/app/core/*"],
			"@layout/*": ["src/app/layout/*"],
			"@page/*": ["src/app/page/*"],
			"@shared/*": ["src/app/shared/*"],
			"@types/*": ["src/app/types/*"]
		}
	},
	"angularCompilerOptions": {
		"enableI18nLegacyMessageIdFormat": false,
		"strictInjectionParameters": true,
		"strictInputAccessModifiers": true,
		"strictStandalone": true,
		"strictTemplates": true
	}
}

You can test it with the following eslint.config.mjs:

import markdown from "@eslint/markdown";
import { defineConfig } from "eslint/config";

export default defineConfig([
    {
        extends: ["markdown/recommended"],
        files: ["**/*.md"],
        language: "markdown/gfm",
        plugins: { markdown },
        rules: {
            "markdown/no-duplicate-headings": "error",
            "markdown/no-html": "error",
        },
    },
]);

Then you should see this error:
image

If you add "exactOptionalPropertyTypes": false to the compilerOptions of the tsconfig.json the error disappears.

@sebastian-altamirano
Copy link
Author

sebastian-altamirano commented May 26, 2025

Here's a repro https://stackblitz.com/edit/vitejs-vite-gantpukn?file=eslint.config.mjs,tsconfig.json&view=editor

I'm not sure why the StackBlitz IDE doesn't display the error, but if you run npx tsc you should be able to see it. Then if you can change exactOptionalPropertyTypes to false in tsconfig.json and rerun the command, the error will no longer be reported.

@nzakas
Copy link
Member

nzakas commented May 27, 2025

@sebastian-altamirano please open an issue on https://github.com/eslint/eslint/issues. The Plugin type exported from eslint is the thing that needs updating to address this.

@nzakas nzakas closed this May 27, 2025
@sebastian-altamirano
Copy link
Author

I created the issue on eslint/eslint#19774.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature repro:needed This issue should include a reproducible example
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants