如何在没有绝对路径的情况下引用打字稿文件? [英] How can I reference typescript files without absolute paths?

查看:33
本文介绍了如何在没有绝对路径的情况下引用打字稿文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 typescript 似乎不支持绝对路径引用,我看不出如何保持我的参考整齐.我的文件夹结构中的许多不同位置都有 ts 文件,并且必须非常小心我的意思是 ..\Scripts\typings\jquery\jquery.d.ts 还是 ..\..\Scripts\typings\jquery\jquery.d.ts 看起来真的很笨拙.

Since typescript doesn't seem to support absolute path references, I can't see how to keep my references tidy. I've got ts files at many different locations in my folder structure, and having to be really careful about whether I mean ..\Scripts\typings\jquery\jquery.d.ts or ..\..\Scripts\typings\jquery\jquery.d.ts seems really kludgy.

是否有任何方法来指定根引用文件夹,这样我就不必指定相对于当前文件路径的所有路径,每个文件夹都不同?

Is there any way to specify a root references folder, so that I don't have to specify all paths relative to the current file path, which is different for every folder?

推荐答案

目前没有办法指定要在引用中使用的 root 文件夹.

There is not currently a way to specify a root folder to use within references.

绝对文件路径确实有效,但通常需要多个开发人员来维护这些路径,这使得这对于许多 TypeScript 开发项目来说可能是不可能的.

Absolute file paths do work, but maintenance of the paths generally speaking with multiple developers makes this likely a non-starter for many TypeScript development projects.

例如在 CodePlex 上有讨论,表达了类似的请求(但没有解决方案).由于 TypeScript 文件是独立的,因此有些人担心向编译器引入类似项目"的方案.

There have been discussions on CodePlex for example that expressed a similar request (but without a resolution). As TypeScript files are stand-alone, some have been concerned about introducing a "project" like scheme to the compiler.

一些开发人员会将最常用的引用放在一个文件中(例如,_references.d.ts)并在那里列出对定义文件的引用.然后,该文件将从其他 TypeScript 文件中引用.它简化了,但并没有完全消除问题(因为您仍然需要使用具有 N 级目录弹出可能性的相对文件引用):

Some developers will put the most commonly needed references in a single file (called for example, _references.d.ts) and list references to the definition files there. Then, that file will be referenced from other TypeScript files. It simplifies, but does not completely eliminate the problem (as you still will need to use relative file references with N levels of directory popping potentially):

/// <references path="../../../_references.d.ts." />

不过,根据您拥有的文件数量和定义的大小,您可能会发现,由于文件是单独编译的,因此编译过程将花费更长的时间(因为它从 _references.d 中提取了可能未使用的定义).ts 文件).(例如,如果您在 IDE 中激活了保存时编译").

Depending on how many files you have and the size of the definitions though, you may find that as files are individually compiled that the compile process will take longer (as it pulls in potentially unused definitions from the _references.d.ts file). (If you have for example, "compile on save" activated within an IDE).

这篇关于如何在没有绝对路径的情况下引用打字稿文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆