小编Rap*_*tro的帖子

如何在 VsCode 中加速 Typescript Intelisense?

这是我的电脑:

  • MacBook Pro(16 英寸,2019 年)
  • 2.3 GHz 8 核英特尔酷睿 i9
  • 16 GB 2667 MHz DDR4
  • 英特尔超高清显卡 630 1536 MB

在 angular 中使用打字稿时会发生这种情况: 在此处输入图片说明

项目越大,我等待加载的时间就越长。真的毁了我的开发者体验。有没有办法可以为 vs 代码分配更多资源,使其运行得更快?我可以做任何优化来使其工作吗?

尝试的解决方案:

示例项目结构:

  • 项目结构

typescript visual-studio-code

11
推荐指数
3
解决办法
1926
查看次数

为什么@angular/fire 显示:'服务器错误。证书已过期”,当我运行时: ng add @angular/fire?

角度版本:

@angular-devkit/architect         0.803.22
@angular-devkit/build-angular     0.803.22
@angular-devkit/build-optimizer   0.803.22
@angular-devkit/build-webpack     0.803.22
@angular-devkit/core              8.3.22
@angular-devkit/schematics        8.3.22
@angular/cli                      8.3.22
@angular/fire                     5.3.0
@ngtools/webpack                  8.3.22
@schematics/angular               8.3.22
@schematics/update                0.803.22
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2
Run Code Online (Sandbox Code Playgroud)

1.什么是'服务器错误。证书已过期'是什么意思?
2. 我该如何解决?

~~~~编辑~~~~

  • 我擦除了我的硬盘并安装了一个全新的操作系统;还是行不通。
  • 在 angular/angularfire git 页面打开了一个问题:https : //github.com/angular/angularfire/issues/2285
  • 发现 angular/fire package.JSON 使用 firebase 工具 6.10.0,当 firebase 工具达到 7.12.1 时试图通过强制项目使用 package.json 中的分辨率解析较新版本的 firebase-tools 并在@wSedlacek 在 GitHub 上的建议。没用。
  • 我将系统时间更改为发生此问题之前,现在可以使用,但问题仍未解决,因为每次要启动项目时将系统时间回滚到 2020 年 1 月 4 日是一个小不便。
  • @wSedlacek 发现 HTTPS 证书即将过期,因为 package.json 中旧版本的 firebase-tools 的证书已于 2020 年 1 月 5 日过期。 …

firebase angular

8
推荐指数
1
解决办法
541
查看次数

在 VS Code 中调试 Angular 代码时如何跳过库

我有一个正在尝试调试的角度项目,但是,当我进行调试过程时,它会进入 @angular/core 和 ts-lib 。这些是包含很多步骤的巨大文件。有没有办法跳过外部代码?

这是我的 launch.json:

"version": "0.2.0",
"configurations": [
    {
        "type": "chrome",
        "request": "launch",
        "name": "Launch Chrome against localhost",
        "url": "http://localhost:4200/silverlakeopc",
        "webRoot": "${workspaceFolder}",
        "skipFiles": ["!**/node_modules/**"]
    }
]
Run Code Online (Sandbox Code Playgroud)

}

当我添加“skipFiles”行时,它现在会跳过我的所有代码。我只是想跳过外部库。

我努力了:

  1. 在 VS Code 中调试时如何跳过外部代码
  2. 如何在可视代码中调试 Angular 7 库
  3. 如何从 VS --debugger-- 中排除节点模块和节点内部组件?

这是我的工作区结构的屏幕截图:
在此输入图像描述

visual-studio-code angular

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

如果 Typescript 中满足条件,如何断言联合类型的类型?

我有一个可以看起来像这样的对象:

{ageTop:42}
Run Code Online (Sandbox Code Playgroud)

或者像这样:

{locations: [{name:Myrtle Beach}]}
Run Code Online (Sandbox Code Playgroud)

这些对象作为参数传递给函数。(我试图确保该函数只获取它可以使用的类型,可能有其中之一,可能有其中两个,也可能没有)

我想出的解决方案如下:

我已经像这样定义了接口:

interface locationsType {
 locations: Array<{name: string}>
}

interface ageTopType {
ageTop: number
}

type keyType = 'ageTop' | 'locations'
Run Code Online (Sandbox Code Playgroud)

我强制执行这样一个事实:如果选择了位置,我们将通过代码中的约定使用locationsType 接口,我相信当某人(或我自己)违反约定时,这会导致错误。我如何通过打字来强制执行此操作?基本上我想创建一些简单的逻辑:

 interface traitType {
   key: keyType
   value: this.key === 'locations' ? locationsType : ageTopType;
}

class Developer {
  locations: []
  ageTop;
  constructor(ageTop,locations) {
  this.ageTop = ageTop
  locations.forEach(_val => this.locations.push(_val))
  }
  loadTrait(trait:TraitType) {
    if(trait.key === location) {
      this.trait.value.forEach(_val => this.locations.push(_val)
      return
    }
  this[trait.key] = trait.value;
 }
}
Run Code Online (Sandbox Code Playgroud)

上面的方法都试过了,还是不行,哈哈。有什么见解吗?

typescript

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

Angular 语言服务在使用 cli 生成的新组件的 vs 代码中不起作用

我有一个较旧的 angular 项目,其中已经制作了一些组件。angular 语言服务不适用于使用 cli 生成的新组件,

今天生成的新组件: HTML 然后这里是 ts 文件: .ts 文件

但是,如果您查看几天前生成的同一项目中的另一个组件,它会起作用:

[工作][1]

.ts 文件: .ts 文件

我认为这是一个 IVY 问题,所以我继续在 angular.json 中禁用 AOT 并在我的 ts 配置中添加了“enableIvy”:false,这是这些文件:

Angular.json

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "frontend": {
            "projectType": "application",
            "schematics": {
                "@schematics/angular:component": {
                    "style": "scss"
                }
            },
            "root": "",
            "sourceRoot": "src",
            "prefix": "app",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist/frontend",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "tsconfig.app.json",
                        "aot": false,
                        "assets": ["src/favicon.ico", "src/assets"],
                        "styles": [
                            "src/styles.scss",
                            "node_modules/material-design-icons/iconfont/material-icons.css"
                        ],
                        "scripts": …
Run Code Online (Sandbox Code Playgroud)

visual-studio-code angular angular-language-service

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