Is it necessary to use Triple-Slash references in Typescript when using "import from"?

Back in the day, older versions of Typescript required adding the well-known

/// <reference

tag to include necessary references. But now, starting from version 1.6, we can import dependencies using the modern ES6 way

import Greeter from "./greeter";

I've been doing some research on this topic, but I'm still not clear on whether or why it's important to completely avoid triple-slash references.

By the way, does the compiler automatically know the order to compile TS files if we utilize filesGlob instead of files in tsconfig.json?

Answer №1

Firstly, it seems that filesGlob is not yet officially supported: https://github.com/Microsoft/TypeScript/issues/1927

Regarding the triple slash reference, it may not be necessary if everything is properly referenced within the files section in tsconfig.json.

If you utilize tools like tsd or typings to manage type definitions for external libraries, they will generate a single file to be included in tsconfig.json; this single file will contain triple slash references to include other files.

For more details on triple slash references, check out the TypeScript Handbook

Answer №2

When working with internal modules/namespaces, it is necessary to use the ///<reference directive to inform the compiler about dependencies and establish the correct order of files in the dependency graph.

The approach you mentioned for ES6 (external) modules can be found at this link. With ES6 modules, file concatenation order is not significant as they are loaded asynchronously.

Therefore, there is no need to include ///<references when using ES6 modules.

Regarding fileGlobs, TypeScript does not currently have this feature, and even if it is added in the future, it is unlikely to impact how file dependencies are resolved within a project. For example, atom-typescript implements fileGlobs but follows a strict policy against relying on JavaScript ordering and only supports manual file ordering in tsconfig.json.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript's ability to pinpoint individual hits stands out as a distinguishing feature

Is there a creative approach to identifying a distinct user using JavaScript, such as generating a hash to transmit to the server-side? EDIT: The challenge is that I am unable to access the browser directly (e.g. set cookies). Additionally, relying on IPs ...

In order to ensure functionality on Firefox 3 and Opera, it is essential to include multiple <script> tags and the <!-- //required for FF3 and

I have utilized Spring Roo to create a basic web project. The user interface is JSP-based with a Tiles layout. Upon examining the default layout code, I noticed that the script tags were defined as: <script src="${dojo_url}" type="text/javascript" > ...

What is the best way to retrieve an object from every function?

I'm dealing with a <div> containing radio buttons: <div id='RB-01'> <span>Item_1</span><input type='radio' name='RB01' value='1'><br /> <span>Item_2</span><inp ...

Is there a feature in impress.js that allows for navigating to the following slide easily?

Impress.js is an innovative web presentation tool created with Javascript. I am interested in setting up custom events to navigate through the slides. This could involve adding buttons for "Next" and "Previous", for example. The impress.js file itself fun ...

From traditional relational databases to MongoDB/Mongoose database design

Recently, I ventured into using mongoDB and mongoose for a new node.js application. Coming from a background of relational databases, I find it challenging to adjust to the mongoDB/noSQL approach, particularly concerning denormalization and the absence of ...

Is XMLHttpRequest just sitting idle...?

As a newcomer to the world of javascript and AJAX, I've been stuck on a single problem for the past 8 hours. Despite my best efforts, I just can't seem to figure out what's going wrong. On my website, I have an image with an onclick event ca ...

The type of jQuery selector

I came across jQuery code that looks like this return 13 == t.keyCode ? (t.preventDefault(), !1) : void 0 Can someone explain what the ? and : mean in this context? Please provide a reference for further reading, as I am still new to jQuery. Thank you ...

Steps to create two interlinked option fields?

I am trying to set up my capital_city autocomplete field in a way that it only displays options related to the selected country_name. Ideally, when a user chooses a country from the dropdown menu, the city field should then show only cities associated with ...

to streamline the process of navigating Google Chrome web pages

Is it possible to create automation in Google Chrome that can complete the following tasks: 1. Input a job name to monitor 2. Periodically click a refresh button on the webpage (not the refresh button for the entire Chrome page in the left corner) 3. Open ...

Sharing a FormGroup between different components

For my Angular 2+ application utilizing reactive forms, I have a requirement to share the main FormGroup across multiple components. This will allow different sections of the form such as header and footer to be managed independently by separate components ...

Automatically generated JavaScript input value calculation

I have 3 text input fields set up as follows: <input type="text" id ="text1"/><br> <input type="text" id ="text2"/><br> <input type="text" readonly="readonly" disabled="disabled" id ="text3"/> The third input is disabled and ...

Error: Unable to retrieve AJAX response

I have reviewed numerous posts regarding this issue and I am unable to understand why I am still receiving 'undefined' for responseText. The expected json format should be {"token": "ghargaeorigjaoregrjarjegijra[pgjpraejgprjgpkfp5p34i5483te8q9rut ...

Combining portions of objects in Angular2

I want to combine two identical type observables in Angular2 and return an observable of the same type in a function. My goal is to: transform this setup: obs1.subscribe(obs => console.log(obs)) (where I receive): { count: 10, array: <some ...

Steps to using the .each method for constructing an array

Currently, we are developing our own webpage within a system and have integrated a form to input timeline data using a .xwd file. To retrieve and store the data, we are utilizing JavaScript by filling it in a variable. Although the main page (title:) only ...

Exploring an array for multiple values using match() function

My goal is to retrieve the object that contains a value matching the searched text. Currently, I achieve this using the return match function. However, I am facing difficulties in testing for numbers within the array. The current implementation only works ...

Using JavaScript to launch a new window for a specific folder

When opening a popup window with a specific URL, I typically use the following code: $("#OpenFolder").click(function () { var url = "https://stackoverflow.com"; windowObjectReference = window.open(url, "ModulesList", " ...

"Adding an active class to a link based on the current page and locale: A step-by-step

Looking to add an active class to the subheader menu on the active page, but facing issues when changing the locale in the link. While it works for links like my-site/my-page, it doesn't work for links like my-site/fr/my-page. Utilizing Storyblok head ...

Is it possible to retrieve JSON data and display only the entries with positive values in an HTML

I am working on a project that involves fetching JSON API data and displaying it in an HTML table, but only for values above 10. Below is the code snippet along with my JavaScript. I specifically want to exclude negative values and only display positive v ...

Tips for accessing information from router.push and implementing it in a separate component

I am currently developing a React app using Next.js. My goal is to pass the userId when pushing the router and then utilize this userId in the Component that I have navigated to. Please refer to the code snippet below: import { useRouter } from "nex ...

Encountering issues with Next JS navigation when using the mobile back button

Recently, I put together a website using Next js 13 (with app router) and utilized Mantine UI for the front-end design. On mobile devices, I have implemented a responsive menu on the homepage. However, when I try to navigate back to the homepage from the ...