小编jon*_*rpe的帖子

Angular 6.0.1 CLI在执行“ ng lint --type-check”时抛出“ Architect”错误

在Angular和Angular CLI更新到v6之后,我的lint配置每次尝试运行时都会引发以下错误ng lint --type-check

具有多个目标的Architect命令不能指定替代。'lint'将在以下项目上运行:atlas-fe,atlas-fe-e2e

错误:具有多个目标的Architect命令无法指定替代。'lint'将在以下项目上运行:
    att -fe,atlas-fe-e2e at LintCommand.validate(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / architect-command .js:75:23)
    位于/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:274:39     位于/ home / nroma的
    Generator.next()
/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:7:71
    在
    __awaiter(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / command-runner.js:3:12)

    在Object的     validateAndRunCommand(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:273:12)中。(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:100:26)
    在Generator.next()
    处已实现(/ home / nroma / workspace / atlas /proto-fe/node_modules/@angular/cli/models/command-runner.js:4:58)

我正在使用节点v9.9.0(npm v6.0.1)

这是我的package.json …

lint angular-cli angular angular6 angular-cli-v6

5
推荐指数
1
解决办法
2682
查看次数

为什么在类没有指定超类时使用super().__ init __(*args,**kwargs)?

我理解为什么当一个类是超类的子类时使用了super(),但是什么是未指定子类参数中的超类的类的超类?这是我的代码:

import random


class Sneaky:
    sneaky = True

    def __init__(self, sneaky=True, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sneaky = sneaky

    def hide(self, light_level):
        return self.sneaky and light_level < 10


class Agile:
    agile = True

    def __init__(self, agile=True, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.agile = agile

    def evade(self):
        return self.agile and random.randint(0, 1)
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
924
查看次数

如何正确处理多种类型的 TypeScript 值

我有以下 TS 接口

export interface Item {
  product: string | Product;
}
Run Code Online (Sandbox Code Playgroud)

当我想遍历项目数组时,我必须消除类型。换句话说

items = Items[];
items.forEach(item => {
  item.product._id
})
Run Code Online (Sandbox Code Playgroud)

不起作用,因为属性不适用于字符串。因此我必须预先检查类型,即:

items = Items[];
items.forEach(item => {
  if (typeof item.product === 'object') item.product._id
})
Run Code Online (Sandbox Code Playgroud)

我真的不喜欢它的样子。你如何处理这种情况?

typescript angular

5
推荐指数
1
解决办法
9317
查看次数

观察者模式遵循/违反哪些可靠原则?

我正在准备考试,目前正在阅读有关观察者模式的内容。然后我想知道观察者模式遵循或违反了哪些SOLID原则?

software-design solid-principles observer-pattern

5
推荐指数
1
解决办法
3350
查看次数

HTTP在Angular 6中调用

我将Angular项目更新为Angular 6,并且不知道如何进行http获取请求.这就是我在Angular 5中的表现:

get(chessId: string): Observable<string> {

this.loadingPanelService.text = 'Loading...';
this.loadingPanelService.isLoading = true;

const url = `${this.apiPathService.getbaseUrl()}api/chess/${chessId}/rating`;   

return this.http.get<string>(url)
.catch((error) => {
    console.error('API error: ', error);

    this.loadingPanelService.isLoading = false;
    this.notificationService.showErrorMessage(error.message);

    return Observable.of(null);
  })
  .share()
  .finally(() => {
    this.loadingPanelService.isLoading = false;
  });
Run Code Online (Sandbox Code Playgroud)

这就是我现在正在做的事情.这是应该如何在Angular 6中完成的吗?

...
return this.http.get<string>(url)
.pipe(
  catchError(this.handleError),
  share(),
  finalize(() =>{this.loadingPanelService.isLoading = false})
);

private handleError(error: HttpErrorResponse) {
console.error('API error: ', error);

this.loadingPanelService.isLoading = false;
this.notificationService.showErrorMessage(error.message);

// return an observable with a user-facing error message
return throwError(
  'Something bad happened; …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-httpclient angular6

5
推荐指数
1
解决办法
2万
查看次数

Jest 测试运行 - 找不到模块错误

我一直在研究 React Typescript 存储库,并且遇到了一个恼人的问题,即开玩笑时无法解析相对于根目录的导入。

 Cannot find module '~lib/dates' from 'utils.ts'
Run Code Online (Sandbox Code Playgroud)

这就是组件/实用程序中导入的样子

import { abc } from '~lib/dates';   // this fails to run
Run Code Online (Sandbox Code Playgroud)

如果我将其更改为相对路径,玩笑测试将按预期运行

import { abc } from '../../lib/dates';   // this runs as expected
Run Code Online (Sandbox Code Playgroud)

同样的路径适用于其他一些目录,我有点困惑

import { xyz } from '~components/home/constants';   // jest resolves it
import { abc } from '~lib/dates';                     // ERR
Run Code Online (Sandbox Code Playgroud)

我尝试将其包含moduleNameWrapper在 jestConfig 中,看看它是否可以正确解析导入,但没有帮助。

包.json

"jest": {
   ...

   "moduleNameWrapper": {
      "^~(.*)$": "<rootDir>/src/$1"
    }
}
Run Code Online (Sandbox Code Playgroud)

我肯定可以更新 VS 代码设置,以便自动导入相对于文件而不是根目录进行解析,但这已经困扰我一段时间了。如果有人能指导如何最好地解决这个问题,那就太好了。

我在一个具有以下目录结构的 monorepo 上

repo
  server
  client
    src
       components
       lib …
Run Code Online (Sandbox Code Playgroud)

javascript typescript jestjs

5
推荐指数
1
解决办法
3万
查看次数

React - Jest RTL 检查元素是否不可见

我有一个直接的反应补偿。我想根据反应状态测试样式。该 comp 如下所示:

反应补偿。

const Backdrop = ({ showBackdrop }) => {
    const backdropRef = useRef();

    function getBackdropHeight() {
        if (typeof window !== 'undefined') {
            return `calc(${document.body.clientHeight}px -
            ${backdropRef.current?.offsetTop || 0}px)`;
        }

        return 0;
    }

    return (
        <div
            data-testid="backdrop"
            className={classNames(styles.backdrop, showBackdrop ? styles.show : styles.hide)}
            ref={backdropRef}
            style={{ height: getBackdropHeight() }}
        />
    );
};
Run Code Online (Sandbox Code Playgroud)

造型

.backdrop {
    width: 100%;
    position: absolute;
    left: 0;
    right: 0;
    top: 156px;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 3;
    ...
}

.show {
    opacity: 0;
    visibility: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-test-renderer react-testing-library

5
推荐指数
1
解决办法
2426
查看次数

更改 ESLint 中的“shouldFix”参数

我正在使用 ESLint 及其 VS Code 扩展来格式化我的代码。

在某些时候,它会停止在保存时自动格式化代码。我卸载了所有内容并重新安装:VS Code、ESLint 和 VS Code 的 ESLint 扩展。

我想我已经接近让格式化程序正常工作了,但是当我尝试保存带有 linting 错误的文件时,ESLint 会将其记录在 VS Code 中:

2020-10-10T10:41:45.345Z eslint:source-code-fixer shouldFix parameter was false, not attempting fixes
Run Code Online (Sandbox Code Playgroud)

我想如果我找到该shouldFix参数并将其设置为true它会起作用,但是它在哪里?

javascript eslint visual-studio-code

5
推荐指数
2
解决办法
3347
查看次数

纱线“错误:EISDIR:对目录进行非法操作,读取”

突然纱线不工作了。Npm 工作正常,但只能运行yarn -v,任何其他命令(例如yarn、yarn test 或yarn watch)都会显示此错误

Arguments: 
  /home/my.user/.nvm/versions/node/v14.15.4/bin/node /home/my.user/.nvm/versions/node/v14.15.4/bin/yarn

PATH: 
  /home/my.user/.nvm/versions/node/v14.15.4/bin:/home/my.user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Yarn version: 
  1.22.10

Node version: 
  14.15.4

Platform: 
  linux x64

Trace: 
  Error: EISDIR: illegal operation on a directory, read

npm manifest: 
  {
    "name": "one",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo 'hello'"
    },
    "keywords": [],
    "author": "",
    "license": "ISC"
  }

yarn manifest: 
  No manifest

Lockfile: 
  No lockfile
Run Code Online (Sandbox Code Playgroud)

node.js yarnpkg yarn-workspaces yarn-lock.json

5
推荐指数
3
解决办法
3万
查看次数

当我尝试在虚拟主机 Ubuntu 中安装 pm2 时,出现“npm WARN deprecated uuid@3.4.0:请升级到版本 7 或更高版本”

每当我尝试在我的虚拟主机中的 Ubuntu 中安装 pm2 时,我都会遇到错误。

命令:

sudo npm install pm2@latest -g
Run Code Online (Sandbox Code Playgroud)

错误:

npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

deployment ubuntu node.js npm pm2

5
推荐指数
1
解决办法
9645
查看次数