eslint-plugin-import-alias icon indicating copy to clipboard operation
eslint-plugin-import-alias copied to clipboard

Type declarations are missing from the distributed package

Open antoninkriz opened this issue 4 months ago • 0 comments

Hello,

when I'm trying to import this package in my eslint.config.ts there are errors in IDEs like VSCode coming from TypeScript:

Could not find a declaration file for module '@dword-design/eslint-plugin-import-alias'. 'whatever/path/to/project/node_modules/@dword-design/eslint-plugin-import-alias/dist/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dword-design__eslint-plugin-import-alias` if it exists or add a new declaration (.d.ts) file containing `declare module '@dword-design/eslint-plugin-import-alias';`ts(7016)

and from typescript-eslint package (if used) when validating eslint.config.ts file:

> eslint .

whatever/path/to/project/eslint.config.ts
  43:31  error  Unsafe member access .configs on an `error` typed value  @typescript-eslint/no-unsafe-member-access

✖ 1 problem (1 error, 0 warnings)

when using the config similar to:

// ...
import eslintPluginImportAlias from '@dword-design/eslint-plugin-import-alias'
// ...

export default tseslint.config([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // ...
      eslintPluginImportAlias.configs.recommended, // <--- Error here
      // ...

Investigation

Since this project is written in TypeScript there, of course, isn't any package with types to install as hinted in the first error.

I saw that you're trying to export types using:

  1. npm run prepublishOnly in the package.json
  2. which calls default export function from @dword-design/base-config-node in prepublish-only.ts from https://github.com/dword-design/base-config-node/blob/master/src/prepublish-only.ts#L15
  3. which calls mkdist --declaration ... ... which should indeed export type definitions according to mkdist's CLI.

But somehow the types did not make it into the final package on NPMJS.

$ ls -R node_modules/@dword-design/eslint-plugin-import-alias/
node_modules/@dword-design/eslint-plugin-import-alias/:
dist  LICENSE.md  package.json  README.md

node_modules/@dword-design/eslint-plugin-import-alias/dist:
index.js  rules

node_modules/@dword-design/eslint-plugin-import-alias/dist/rules:
prefer-alias.js

Maybe I'm missing something? Would it be possible to include the types?

Workaround

Currently I use a following workaround. I created file dword-design_eslint-plugin-import-alias.d.ts

declare module '@dword-design/eslint-plugin-import-alias' {
  export = {
    configs: {
      recommended: {
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        plugins: any,
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        rules: any,
      },
    },
  }
}

which I included in my tsconfig.json

{
    // ...
    "include": [
        // ...
        "dword-design_eslint-plugin-import-alias.d.ts"
    ]
}

and I imported the file at the top of eslint.config.ts

import './dword-design_eslint-plugin-import-alias.d.ts'

// ...

antoninkriz avatar Jul 31 '25 13:07 antoninkriz