-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Not able to detect .d.ts file #261
Comments
Have you tried using the TS import resolver? |
@ljharb What is it? |
@ljharb First of all I want to why this is happening. Do you have any idea on it? |
https://www.npmjs.com/package/eslint-import-resolver-typescript - I see that you're extending our TS config tho https://github.com/import-js/eslint-plugin-import#typescript so as long as that package is installed you should be good. |
cc @JounQin who may be able to help |
@ljharb Just to make sure, these are the plugins and dev dependencies that I have installed, am I missing something? "devDependencies": {
"@babel/core": "^7.22.1",
"@babel/preset-env": "^7.22.4",
"@babel/preset-react": "^7.22.3",
"@babel/preset-typescript": "^7.21.5",
"@types/react": "^18.2.7",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"babel-loader": "^9.1.2",
"css-loader": "^6.8.1",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.5.1",
"prettier": "^2.8.8",
"style-loader": "^3.3.3",
"typescript": "^5.0.4",
"typescript-plugin-css-modules": "^5.0.1",
"webpack": "^5.84.1",
"webpack-cli": "^5.1.1",
"webpack-dev-server": "^4.15.0",
"webpack-merge": "^5.9.0"
} |
yes, you need |
@ljharb Ok will try it, |
d.ts files are typescript files. They can't be resolved by default because |
Got it, then what was the use of "@typescript-eslint/eslint-plugin", was't it to provide the same thing?. |
That provides the parser - which is different from the resolver. |
@ljharb I tried with "eslint-import-resolver-typescript" settings: {
react: {
version: 'detect',
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
}, |
The settings are already in import/typescript so you just need to install the package. If it's still not working, then there's clearly something wrong, I'm just not sure what it is. |
Yeah, I have installed the package. Looks like something is not correct. |
I'm having this issue as well. This is my ESLint config. module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
sourceType: 'module',
},
plugins: ['import', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'prettier',
],
settings: {
'import/resolver': {
typescript: {},
},
},
ignorePatterns: ['*.config.*', '*.cjs'],
} It fails to work with with a simple directory setup like this: src
├── index.ts
└── app.d.ts // src/index.ts
import {} from 'app' // src/app.d.ts
declare module "app" {} I "declare" that a module exists in an ambient |
It is indeed a missing feature from |
I am having a react typescript project with eslint and typescript setup with webpack.
I created one declaration.d.ts file having this code
When I am importing it. I am getting a eslint error
Unable to resolve path to module 'local-react'.eslint[import/no-unresolved](https://github.com/import-js/eslint-plugin-import/blob/v2.27.5/docs/rules/no-unresolved.md) module "local-react"
I am not sure why this is happening and what's the issue, I think typescript is able to resolve this that's why I am not getting the typescript error, because my include file in src consist of "src/**/*", but what about eslint?
This is my ts config,
This is my eslint config file
The text was updated successfully, but these errors were encountered: