I am facing an issue with my TypeScript configuration. I have two files in /src/models/: User.ts and User.d.ts. In User.ts, I am building a class and trying to use an interface declaration for an object defined in User.d.ts. However, User.ts is unable to automatically recognize the interface from User.d.ts. I thought TypeScript parses all .d.ts files by default, so I'm confused about why it's not working. Do I need to update my config settings or am I missing something in my understanding?
The error message I receive pertains to the User.d.ts file:
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/models/User.d.ts.
The file must be included in at least one of the projects provided
Within User.ts:
class User {
private id: number;
constructor(id: number) {
this.id = id;
}
static create(userData: UserData): User | undefined {
return undefined;
}
getId(): number {
return this.id;
}
}
export default User;
In UserData.d.ts:
interface UserData {
id?: number;
gmail?: string;
firstName?: string;
lastName?: string;
loginIP?: string;
secureKey?: string;
imgFileName?: string;
lastUpdate?: string;
createDate?: string;
}
I am struggling to make User.ts recognize UserData. Here are excerpts from my tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true
},
"include": ["/src/**/*.ts", "**/src/**/*.ts", "**/__tests__/**/*.ts"]
}
And from my .eslintrc.js file:
module.exports = {
extends: ['airbnb', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {},
},
},
rules: {
'import/no-extraneous-dependencies': [2, { devDependencies: ['**/*.test.tsx', '**/*.test.ts'] }],
'@typescript-eslint/indent': [2, 2],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
mjs: 'never',
},
],
},
};
I would greatly appreciate any assistance in figuring out where I am going wrong. Thank you.