typescript-eslint: Bug: [consistent-type-imports] can not support when using DI of nest.js
Before You File a Bug Report Please Confirm You Have Done The Following…
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
import { schedule } from 'node-cron';
import { mergeOptions } from '@hyperse-hub/vendure-common';
import { Inject, Logger, type OnApplicationBootstrap } from '@nestjs/common';
import type { EventBus, RequestContextService } from '@vendure/core';
import {
type DeepPartial,
PluginCommonModule,
type Type,
VendurePlugin,
} from '@vendure/core';
import { loggerCtx, PLUGIN_INIT_OPTIONS } from './constants.js';
import { CronEvent } from './cron-event.js';
import {
type PluginInitOptions as CronInitOptions,
type PluginInitOptions,
} from './types.js';
@VendurePlugin({
imports: [PluginCommonModule],
providers: [
{
provide: PLUGIN_INIT_OPTIONS,
useFactory: () => HyperseVendurePluginCron.options,
},
],
compatibility: '>=3.0.0',
})
export class HyperseVendurePluginCron implements OnApplicationBootstrap {
static options: CronInitOptions = { cron: [], logEvents: false };
constructor(
@Inject(PLUGIN_INIT_OPTIONS)
private options: PluginInitOptions,
private eventBus: EventBus,
private requestContextService: RequestContextService
) {}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false },
],
},
};
tsconfig
{
"compilerOptions": {
"strict": true,
"sourceMap": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"importsNotUsedAsValues": "preserve",
"noImplicitReturns": false,
"baseUrl": ".",
"rootDir": ".",
"outDir": "dist",
"isolatedModules": true,
"paths": {}
}
}
Expected Result
import { EventBus, RequestContextService } from ‘@vendure/core’; should not convert into import type { EventBus, RequestContextService } from ‘@vendure/core’;
Actual Result
import { EventBus, RequestContextService } from ‘@vendure/core’; to import type { EventBus, RequestContextService } from ‘@vendure/core’;
Additional Info
https://github.com/typescript-eslint/typescript-eslint/pull/5904 i found this PR , but it seems that above codes have been removed from latest typescript/estlint?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (13 by maintainers)
Ok, makes sense! Here’s what I think is happening:
So, without type information being set up, ie via
parserOptions.projectorparserOptions.projectService(whether or not any rules requiring type information are actually used), consistent-type-imports has no way of knowing what’s actually in your tsconfig. And it assumes by default that experimentalDecorators and emitDecoratorMetadata are false. Therefore, unless you manually specify those options in your parserOptions, it will report on the types used in the decorator.This caveat is documented here.
Does that explain what you’re seeing?
i have used like this
My project statement is as follows type:module nodenext,It works fine locally and doesn’t prompt any configuration errors