简体   繁体   English

如何摆脱

[英]How to get rid of <reference path="

Sorry everyone, I've been struggling trying to understand why I need the对不起大家,我一直在努力理解为什么我需要

/// <reference path="../typings/browser.d.ts" />

module App {
    angular.module("app", [""]);
}

I'm using typings and here is my tsconfig :我使用的是typings ,这里是我的tsconfig

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs"
  },
  "files": [

  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

I found already several posts about, but every time a different answer and a different scenario.我已经找到了几篇关于的帖子,但每次都有不同的答案和不同的场景。

I use Visual Studio 2015 with ReSharper , TypeScript 1.8.5我将Visual Studio 2015ReSharperTypeScript 1.8.5

Once I remove <reference... tag ReSharper says "Cannot find name 'angular'" but the application runs normally.一旦我删除<reference...标签, ReSharper“找不到名称‘角度’”,但应用程序运行正常。 (probably because it cannot find the intellisense anymore) (可能是因为它再也找不到智能感知了)

Has anyone faced the same problem?有没有人遇到过同样的问题? Am I missing something?我错过了什么吗?

From the docs on tsconfig :tsconfig文档

If no "files" property is present in a tsconfig.json, the compiler defaults to including all TypeScript (*.ts or *.tsx) files in the containing directory and subdirectories.如果 tsconfig.json 中不存在“files”属性,则编译器默认将所有 TypeScript(*.ts 或 *.tsx)文件包含在包含目录和子目录中。 When a "files" property is present, only the specified files are included.当存在“文件”属性时,仅包含指定的文件。

You are using an empty files array ( "files": [] ) which means no files are going to be included in the compiler context.您使用的是空文件数组( "files": [] ),这意味着编译器上下文中不会包含任何文件。 Either add all your references to the files array, or remove the files property completely to allow the compiler to include all TS files in context.添加对files数组的所有引用,或者完全删除files属性以允许编译器在上下文中包含所有TS 文件。

Alternatively, you can use import and export module syntax instead.或者,您可以改用importexport模块语法。

I use one _reference.ts file with all referenced *.d.ts lybraries which I use.我使用一个 _reference.ts 文件,其中包含我使用的所有引用的 *.d.ts 图书馆。 The typescript compiler use it information for import defenitions about js lybraries.打字稿编译器将其信息用于有关 js 库的导入定义。 The second case there reference are used is managing the order of ts files include into resulting js file.使用参考的第二种情况是管理包含到结果 js 文件中的 ts 文件的顺序。 Another words if you add reference in file B.ts to A.ts in resulting js will be contains A.js first and B after.换句话说,如果您在文件 B.ts 中添加对 A.ts 的引用,则生成的 js 将首先包含 A.js,然后包含 B。 It's not often needed because TSC is smart and ordered file by types using but some times It's usefull then you use some suff from A.ts in B.ts dynamicly (not stronrly typed).它不是经常需要的,因为 TSC 是智能的并且按使用的类型对文件进行排序,但有时它很有用,然后您可以动态地在 B.ts 中使用 A.ts 中的一些内容(不是强类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM