playwright-community / eslint-plugin-playwright

ESLint plugin for Playwright
https://www.npmjs.com/package/eslint-plugin-playwright
MIT License
281 stars 39 forks source link

Types are wrong #330

Closed haines closed 1 week ago

haines commented 1 week ago

I get TypeScript errors when attempting to use this plugin. It seems like the types are wrong.

This has a type error (Property 'configs' does not exist) but works at runtime:

import playwrightPlugin from "eslint-plugin-playwright";
import { config as defineConfig } from "typescript-eslint";

export const playwrightConfig = defineConfig(
  playwrightPlugin.configs["flat/recommended"],
);

This type-checks successfully but fails at runtime (TypeError: undefined is not an object (evaluating 'playwrightPlugin.default.configs'):

import playwrightPlugin from "eslint-plugin-playwright";
import { config as defineConfig } from "typescript-eslint";

export const playwrightConfig = defineConfig(
  playwrightPlugin.default.configs["flat/recommended"],
);

My experience seems to be consistent with the issues reported by "Are The Types Wrong?"

https://arethetypeswrong.github.io/?p=eslint-plugin-playwright%402.0.0

❗️Incorrect default export

The resolved types use export default where the JavaScript file appears to use module.exports =. This will cause TypeScript under the node16 module mode to think an extra .default property access is required, but that will likely fail at runtime. These types should use export = instead of export default.

🎭 Masquerading as CJS

Import resolved to a CommonJS type declaration file, but an ESM JavaScript file.

mskelton commented 1 week ago

Please share a reproduction code sandbox or repo. The types only matter for the ESM build which is used for the flat config, the commonjs export is only for legacy config files which don't need the types.

haines commented 1 week ago

Hi @mskelton, here's a minimal repro: https://github.com/haines/eslint-plugin-playwright-types-are-wrong

mskelton commented 1 week ago

Fixed in 4c61256978556570b4f528eb2ba932ebee110609 and faee198b68b1e134ed389b09c0b663011a556d9e

haines commented 1 week ago

Thanks!