简体   繁体   中英

Import sources within a group must be alphabetized. Typescript

So I have the Import sources within a group must be alphabetized. error in the following file:

login.view.tsx

import AbstractComponent from "../abstract-component";
import { LoginController } from "./login.view.controller";
import { UserService } from "../../services/user.service";
import { IBaseProps } from "../../App";

export interface ILoginProps extends IBaseProps {
    userService?: UserService;
  }

  class Login extends AbstractComponent<ILoginProps, object> {
    private loginController: LoginController;

    constructor(public props: Readonly<ILoginProps>) {
      super(props);
      this.loginController = new LoginController(this, props);
    }
}

My tsconfig.json is the following:

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src"
  },
  "rules": {
    "ordered-imports": [
      false
    ]
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

I tried to change the order of all the imports with results. Can anyone help me out?

This is not a typescript's error, but tslint's one. It wants you to rearrange the import statements in alphabetical order.

I think, like this (but I am not sure, so try different orders yourself):

import AbstractComponent from "../abstract-component";
import { IBaseProps } from "../../App";
import { LoginController } from "./login.view.controller";
import { UserService } from "../../services/user.service";

If nothing works, try tslint's auto fix command:

tslint --fix

If you use VSCode, then put the cursor on the red-underlined statements and press ctrl + . , it will suggest auto fix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM