gpt4 book ai didi

javascript - 如何在不使用任何引用的情况下编译 TypeScript

转载 作者:行者123 更新时间:2023-11-30 16:48:44 26 4
gpt4 key购买 nike

请原谅我的误解,但我认为如果我使用 tsconfig.json文件在我的项目根目录下,那么我将不再需要使用任何 ///<reference path="..." />标签以使我的代码编译。我错了吗?

例如,我正在使用 AngularJS。我的App.ts文件看起来像这样:

import SomeModule from './whatever/SomeModule';

angular.module('foo', [SomeModule.name]).run(...);

我的 tsconfig.json文件看起来(部分)像这样:

{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"filesGlob": [
"./www/**/*.ts",
"./typings/**/*.ts"
],
"files": [
/* a bunch of files omitted for brevity*/
"./typings/angularjs/angular.d.ts"
],
}

请注意,我在我的文件数组中列出了 Angular 定义文件的路径。另请注意,我有 compileOnSave选项设置为假。最终我想使用 Browserify 来编译和捆绑所有代码。但现在我只想看看我是否可以用 tsc 编译它.

但是当我运行 tsc App.ts ,我收到一条错误消息“找不到名称‘angular’”。如何使 TypeScript 编译使用 angular.d.ts编译代码时的文件?

最佳答案

运行 tsc App.ts 将不起作用,因为正在指定文件。按照文档中的说明进行操作:

Using tsconfig.json

  • By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.
  • By invoking tsc with no input files and a -project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

When input files are specified on the command line, tsconfig.json files are ignored.

Source

关于javascript - 如何在不使用任何引用的情况下编译 TypeScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30851882/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com