zardoy / typescript-vscode-plugins

NO LIMITS FOR TS! Isn't this the most advanced TypeScript plugin as VS Code extension ever created?
https://marketplace.visualstudio.com/items?itemName=zardoy.ts-essential-plugins
MIT License
53 stars 5 forks source link

auto import exclude specific member from module #215

Open tjx666 opened 6 days ago

tjx666 commented 6 days ago

I use next-nprogress-bar in my next.js project, but ts will sometimes import useRouter from next-nprogress-bar which is not my expected:

import { useRouter } from 'next-nprogress-bar';

export function useRenderPageAsComp(pagePathname: string) {
  const { pathname } = useRouter();
  return pathname !== pagePathname;
}

Solution

depracetd old seeting suggestions.ignoreAutoImports" and extend it to `suggestions.autoImports":

"suggestions.autoImports": [
  {
    "modules": ["path"], // ignore path, but not path/posix or path/win32 modules,
    "members": []
  }
  {
    "modules": ["next-nprogress-bar"],
    "excludeMembers": ["useRouter"] // will exclude useRouter from next-nprogress-bar
  },
  {
    "modules": ["@mui/material"],
    "excludeMembers": ["SxProps"] // will exclude type SxProps from @mui/material
  },
  {
    "modules": ["@mui/system"],
    "members": ["SystemCssProperties"], will exclude all other members except for `SystemCssProperties`
  }
]

Maybe you can get some inspiration from https://eslint.org/docs/latest/rules/no-restricted-imports

zardoy commented 5 days ago

Most of things are available now, but that's a great idea to rework the setting to make it easier to configure