打字稿。当使用“从”导入“时,仍然需要三重斜杠引用。 [英] Typescript. Are Triple-Slash references still required when using "import from"

查看:152
本文介绍了打字稿。当使用“从”导入“时,仍然需要三重斜杠引用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧版本的Typescript中,需要添加着名的

In old versions of Typescript it was required to add the famous

/// <reference

标签添加所需的引用。现在,在 1.6 之后,我们可以使用推荐的ES6方式导入依赖项。

label to add the required references. Now after version 1.6 we can import dependencies using the recommended ES6 way

import Greeter from "./greeter";

我一直在阅读一段时间,但我仍然不清楚,必须完全避免使用斜杠参考。

I have been reading for a while but it is still not clear to me whether and why the triple-slash references must be completely avoided or not.

BTW。现在,如果我们使用 filesGlob 而不是文件,编译器会按照哪个顺序编译TS文件tsconfig.json?

BTW. Will now the compiler know in which order it has to compile the TS files if we are using filesGlob instead of files in the tsconfig.json?

推荐答案

首先,我不相信 filesGlob 正式支持: https://github.com/Microsoft/TypeScript/issues/1927

First off, I don't believe filesGlob is officially supported yet: https://github.com/Microsoft/TypeScript/issues/1927

现在就三重斜杠引用而言,不需要像 files 在tsconfig.json 。

Now as far as the triple slash reference, it is not required as long as everything is referenced in files in tsconfig.json.

你会发现,如果你使用一个工具,如 tsd 打字来管理外部库的类型定义,他们将创建一个包含在tsconfig.json中的单个文件;单个文件将使用三重斜杠引用来包含其余的文件。

You'll find that if you use a tool like tsd or typings to manage type definitions for your external libraries, they will create a single file that you include in tsconfig.json; that single file will use triple slash references to include the rest of the files.

您可以在<一个href =http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html =nofollow> TypeScript手册

这篇关于打字稿。当使用“从”导入“时,仍然需要三重斜杠引用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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