簡體   English   中英

組中的導入源必須按字母順序排列。 打字稿

[英]Import sources within a group must be alphabetized. Typescript

因此,我必須按字母順序在組中的“ 導入”源。 以下文件中的錯誤:

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);
    }
}

我的tsconfig.json是以下內容:

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"
  ]
}

我試圖更改所有導入結果的順序。 誰能幫我嗎?

這不是打字稿的錯誤,而是tslint的錯誤。 它希望您按字母順序重新排列導入語句。

我認為是這樣的(但我不確定,因此請自己嘗試其他命令):

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

如果沒有任何效果,請嘗試tslint的自動修復命令:

tslint --fix

如果使用VSCode,則將光標放在帶紅色下划線的語句上,然后按ctrl + . ,它將建議自動修復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM