- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个一对一双向的实体类型:
部门:
@Entity('Departament')
export default class Departament {
@PrimaryGeneratedColumn()
id: string;
@Column()
departament_name: string;
@OneToOne(type => User, user => user.departament)
@JoinColumn()
user: User;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at' })
UpdatedAt: Date;
}
用户:
@Entity('User')
export default class User {
@PrimaryGeneratedColumn()
id: string;
@Column()
name: string;
@Column()
last_name: string;
@Column()
email: string;
@Column()
login: string;
@Column()
password: string;
@OneToOne(type => Departament, departament => departament.user)
departament: Departament;
}
这些是我的 .eslintrc 设置:
{
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": "error",
"no-new": "off",
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"no-await-in-loop": "off",
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["**/*.spec.ts", "src/utils/tests/*.ts"]
}
],
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "_"
}
],
"@typescript-eslint/no-useless-constructor": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "off"
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
],
"settings": {
"import/extensions": [".ts", ".js"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".js"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
}
}
我遇到了这个错误:
dependency cycle detected.eslintimport/no-cycle
关于(用户和部门)
和:
'type' is defined but never used. Allowed unused args must match/_/u.eslint@typescript-eslint/no-unused-vars
我无法解决这个问题,我不知道最好的选择是什么,我正在关注 typeorm 的入门
最佳答案
循环导入的某些情况可能会让编译器感到困惑,但大多数情况下它们可以毫无问题地解决。 eslint import/no-cycle
规则的存在是为了尽早消除任何潜在的问题,这是一件好事。有一个优秀的Stack Overflow answer这更清楚地说明了这个问题,并建议完全避免循环依赖。
有a discussion在提供多种解决方案的 TypeORM 存储库中,每个解决方案都有自己的权衡。最完整的解决方案是entity schemas和 string references .两种解决方案都使用类似的想法——定义与字符串的关系并在稍后解析字符串。
这是解决循环依赖的常用方法,可以在其他 ORM 中找到,例如 Python 的 SQLAlchemy 或 Ruby on Rails 的 ActiveRecord。这个想法很简单:实体类/模式是通过实体的名称字符串从注册表中检索的,这消除了显式导入模块来定义关系的需要。
让我举两个例子。
这是一种定义实体的实用方法。类定义被替换为 EntitySchema
的实例,并且没有使用装饰器。
export const DepartmentEntity = new EntitySchema({
name: "Department",
columns: { /* omitting for brevity */ },
relations: {
user: {
type: "one-to-one",
target: "User"
}
}
})
export const UserEntity = new EntitySchema({
name: "User",
columns: { /* omitting for brevity */ },
relations: {
department: {
type: "one-to-one",
target: "Department"
}
}
})
这对您已有的内容进行了不太彻底的更改,它只需要将类型函数和逆侧函数更改为字符串。要正确键入关系属性,您需要使用 import type
:
import type User from './user';
@Entity('Department')
export default class Department {
// omitting most of the columns
// ...
@OneToOne('User', 'department')
@JoinColumn()
user: User;
}
import type Department from './department';
@Entity('User')
export default class User {
// omitting most of the columns
// ...
@OneToOne('Department', 'user')
department: Department;
}
这取决于你。机制完全相同,但实体模式很可能会留下并成为 TypeORM 中的一等公民 versions to come并且它们为您提供了比类所提供的更多的类型安全性。
关于typescript - 检测到依赖循环.eslint with typeorm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62980221/
我遵循文档中的说明 https://www.gatsbyjs.org/docs/eslint/ ,并想覆盖其中一条规则,但不影响其他规则,我所做的是创建一个 .eslintrc.js 文件。 这是文件
是否可以覆盖 TSLINT (tslint.json) 中特定文件的规则,就像沿着这些行的配置一样: "overrides": [{ "files": [ "*.spec.js" ], "ru
我一直试图让 ESLint 在 VS Code 中处理一个新的 Angular 项目,但它无法加载“@typescript-eslint/eslint-plugin”。在过去的 3 个小时里,我一直在
我在某个文件夹中有一些文件,而这些文件来自供应商,因此我无法控制它们。我想为该目录和所有子文件夹中的所有文件禁用 eslint。 最佳答案 您可以添加 .eslintignore在项目根目录下,和.g
我第一次尝试使用汇总,但我不明白为什么会出现此错误: TypeError: eslint is not a function 我之前安装了 rollup (v1.1.0) 然后 eslint npm
我正在尝试使用预提交 Hook 在提交发生之前检测 eslint 错误。我正在使用 husky 和 lint-staged。但它对 src 中的所有文件运行 lint 命令,而不是仅对暂存文件运行
我不确定我正在使用的东西是否存在错误,或者我是否只是在这里设置了错误,但是我在运行 eslint src --fix 关于“eslint-plugin-@typescript-eslint” 我已经指
我正在按照说明从 here 设置 ESLint . ESLint 失败并显示以下消息: $ npm run lint > IACS@1.0.0 lint /some/path/sscce-typesc
我正在使用 airbnb-eslint 和 babel-plugin-module-resolver。我在使用别名导入的每个 js 文件中都收到此错误。 { "extends": ["plugi
我正在将我的项目从 tslint 重新配置为 eslint。我可以手动运行 eslint,但 webpack 无法运行并显示以下错误消息: Module build failed (from /pat
我正在尝试使用 svelte 制作一个应用程序来试用它。 我想设置 prettier 和 eslint,我安装了这些依赖项和 Svelte for VS Code 的扩展。 "dependenci
我正在寻找一个规则来对齐所有 =在任务上。 像这样的事情将是积极的: var foo = 12; var barfoo = 21; var barfoobar = 22; 像这样的事
设置后eslint并在忽略列表中添加一些文件,每次运行 eslint 时,它都会生成有关被忽略文件的警告: /path/to/file/name.min.js 0:0 warning Fil
是否可以将 ESLint 配置为仅将规则应用于名称与特定模式匹配的文件?我知道在目录中可以有单独的规则表,但如果结构如下: app | |- module1 | |- module1.js |
有没有办法禁用文件夹的特定规则?例如,我不希望 test 文件夹中的所有测试文件都包含必需的 JSDoc 注释。有办法做到这一点吗? 最佳答案 要从 eslint 规则中忽略某些文件夹,我们可以在根目
缩进规则似乎无法禁用;如何(在配置设置中)禁用此规则?谢谢。 最佳答案 将规则设置为 "off"在你的配置中是这样的: "rules": { "indent": "off" } 您可以在 the
ESLint 有 dot-location允许决定您是否愿意的规则 object. property 或者 object .property 当打破点时(我更喜欢后者)。 但是,我找不到确保点与对象具
这些库之间有什么区别? babel-eslint [ github.com/babel/babel-eslint ] eslint-plugin-babel [github.com/babel/esl
我想把 Prettier 和 ESLint 一起用,但是一个接一个用就遇到了一些冲突。我看到有这三个包似乎允许它们串联使用: prettier-eslint eslint-plugin-prettie
我正在尝试使用React.js和TypeScrip在ASP.NET核心MVC项目中启用eslint linting,并且正在努力修复上面的错误。。我使用的是Visual Studio2022社区版17
我是一名优秀的程序员,十分优秀!