Angular中的Typescript编译器

问题描述 投票:0回答:1

我想知道,是否有某些选择,如何从TSC命令中排除node_modules软件包。

我正在使用Typescript v3.5.3。我的tsconfig.json是

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es2018", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "typeRoots": ["node_modules/@types"]
  },
  "exclude": [
    "build",
    "config",
    "node_modules"
  ],
  "include": [
    "src"
  ]
}

还有这样一个有角度的脚本

import { Component } from "@angular/core";

@Component({
  selector: "app-home",
  styleUrls: ["./home.component.less"],
  templateUrl: "./home.component.html"
})
export class HomeComponent {
  title = "angular home";
  
  constructor(){
    this.log(123);
    this.log('hello world');
  }

  log(someArg) {
    console.log(someArg);
  }
}

现在,如果我将运行TSC,我会期望出现错误,因为函数日志具有隐式任何类型。在这种情况下,一切正常!但是,如果我将使用此代码

import { Node } from "@alfresco/js-api";
import { Component } from "@angular/core";

@Component({
  selector: "app-home",
  styleUrls: ["./home.component.less"],
  templateUrl: "./home.component.html"
})
export class HomeComponent {
  title = "angular home";
  selectedNode: Node;
  
  constructor(){
    this.log(123);
    this.log('hello world');
  }

  log(someArg) {
    console.log(someArg);
  }

}

我将从类似node_modules的包中得到错误

node_modules/@alfresco/js-api/src/authentication/processAuth.ts:181:9-错误TS2322:类型'null'无法分配给类型'string |未定义”。

181 this.authentications.basicAuth.username = null;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]

我知道为什么,因为“ noImplicitAny”设置为true,但是我要忽略的是node_modules包!因此,在tsconfig中的Angular exclude选项中,没有任何意义。我认为,构建是包@ alfresco / js-api包含到脚本中并作为一个检查的。

有趣的是,如果我将在React.js中使用类似的代码,那么一切都是我所期望的。当我将命令“ TSC”与“ noImplicitAny” = true一起使用时,node_modules软件包将被忽略吗?非常感谢!

我想知道,是否有某些选择,如何从TSC命令中排除node_modules软件包。我正在使用Typescript v3.5.3。我的tsconfig.json是{“ compilerOptions”:{“ outDir”:“ build / ...

angular typescript tsc
1个回答
0
投票

使用import

© www.soinside.com 2019 - 2024. All rights reserved.