Having trouble with TypeScript configuration of typeRoots and types functionality not functioning correctly

My Current Directory Structure

Let me show you the layout of my files:

root
├──typings/           # currently empty
├──package.json
├──package-lock.json
├──tsconfig.json
└──main.ts

This is what my tsconfig.json looks like:

{
    "compilerOptions": {
        "typeRoots": [
            "./typings"
        ],
        "types": ["Phaser"]  
    }    
}

Inside my main.ts file, I have the following line of code:

let countdownNumber: Phaser.GameObjects.BitmapText;

After running the command below in terminal:

tsc --traceResolution

My intention was to use Phaser as a global variable in my main.ts file.

Expected Outcome:

My expectation was that Phaser would not be resolved because the compiler should search within my custom folder typings.

Actual Result:

To my surprise, Phaser still got resolved. Here is the information it provided:

Type reference directive 'Phaser' was successfully resolved to '/Applications/XAMPP/xamppfiles/htdocs/phasertest/node_modules/Phaser/types/phaser.d.ts' with Package ID 'phaser/types/[email protected]', primary: false.

I am unsure as to how it found it, considering that I did not specify node_modules in my typeRoots.

My Attempts to Resolve:

In an effort to exclude the node_modules folder, I experimented with different configurations of the exclude option, but unfortunately, none of them yielded the desired result:

  • "exclude": ["node_modules/*"]
  • "exclude": ["./node_modules/*"]
  • "exclude": ["./node_modules"]

Regrettably, none of these approaches were successful.

Answer №1

It seems like this behavior is intentional, although I agree that it may not be immediately obvious

As stated in the tsconfig documentation found at Types > What does this affect?

The inclusion of @types/* in your application code is not impacted by this option. For instance, if you have the following compilerOptions example:

import * as moment from "moment";
moment().format("MMMM Do YYYY, h:mm:ss a");

The import of moment would still be fully typed.

With this option enabled, omitting a module from the types array means:

  • Global declarations will not be added to your project (e.g. process in Node.js, or expect in Jest)
  • Exports will not be suggested for auto-import

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

KineticJS: Applying a filter to an image does not result in the image having a stroke

Working with KineticJS version 5.1.0 I encountered an issue where a KineticJS image that had a stroke lost the stroke after applying a filter to it. I have created a demo showcasing this problem, which can be viewed on JSFiddle. Here is the code snippet: ...

Error in MEAN CRUD operation cannot be determined

{ text: undefined, done: false, _id: 529e16025f5222dc36000002, __v: 0 } PUT /api/todos/529e16025f5222dc36000002 200 142ms - 68b Encountering an issue while updating my CRUD todo list. Despite receiving a successful status code of 200 after submittin ...

Looking to generate a computed attribute?

Trying to adjust the font size of text using a dropdown and so far it's working as expected. However, is there a more efficient way to achieve this, such as using a computed property or watcher? I'm not sure how to go about implementing that. He ...

Types of Axios responses vary depending on their status codes

I am looking to create a specific type for axios responses based on the status code: types: type SuccessfulResponseData = { users: .... }; interface SuccessfulResponse extends AxiosResponse<SuccessfulResponseData, any> { status: 200; } ty ...

Guide: Implementing material-ui theme with redux in gatsby

I'm currently utilizing the material-ui theme in conjunction with redux-toolkit within a gatsby project. This is my theme.ts file: import { createMuiTheme } from "@material-ui/core"; import { useSelector } from "react-redux"; import { State } from ". ...

Deleting the First Item from an Array in Typescript using Angular

Clicking my Button in .html <button (click)="deleteFirst()">Delete First</button> My array setup and removal function in .ts: people = [ {first: "Tom", last: "Brown"}, {first: "Ben", last: &qu ...

Tips for handling binary data retrieved from a SQL query (such as LONGBLOB type) in node.js

I am trying to send binary data to the client using node.js, but I have encountered a limitation where write can only send string or Buffer. How can I successfully send binary data to the client? dbconnect.selectBinary(conn,function(result) { //resul ...

Struggling with AngularJs as I attempt to retrieve my Twitter timeline. It's been a challenge

Currently, I am using the code below to fetch tweets for a timeline. This snippet was originally taken from an AngularJS tutorial and worked perfectly with Twitter's search API. angular.module( 'Twitter', [ 'ngResource' ]); func ...

Proper method for updating a component prop in Vue.js from within its method

Here is the code snippet for a Vue.js component: var list = Vue.component('list', { props: ['items', 'headertext', 'placeholder'], template: ` <div class="col s6"> <div class="search"> ...

The property cannot be set for an undefined element in Jquery UI slider tabs

There seems to be some extra space at the bottom of the slider tabs between the navigators and content. Additionally, I am facing a challenge in making the page responsive as the content size does not adjust when I resize the window. To see the changes, I ...

Customize specific styles for individual divs one at a time (without the use of jQuery)

Can you assist me with this issue? I am trying to display the <span class="badge badge-light"><i class="fa fa-check-circle"></i></span> tag (initially set to "visibility: hidden") when clicking on a div with the class "role-box". He ...

Error: The function initMap() is not recognized in the Google Maps API

I have been experimenting with the Flickr API and I'm currently working on asynchronously loading images along with their metadata. To accomplish this, I have a script that utilizes three AJAX calls: $(document).ready(function() { var latLon = { ...

AngularJs monitoring changes in service

Why does changing the message in the service not affect the displayed message in 1, 2, 3 cases? var app = angular.module('app', []); app.factory('Message', function() { return {message: "why is this message not changing"}; }); app ...

Tips for utilizing ng-repeat with a function that generates a fresh object?

My HTML code includes the following element: <button ng-click="console.log(key)" ng-repeat="(key, value) in getLocalStorageKeys() track by $index"> In my JavaScript file, I have the following function: $scope.getLocalStorageKeys = function(){ ...

Exploring the synergies of Next.js and Node.js thread pooling

In my current project, I am utilizing nextJS with NodeJS and looking to implement child processes or workers. The code provided by NextJS itself is functioning perfectly. The relevant code snippets: NextJS with NodeJS Another resource I referred to: Nex ...

Swapping values in JSON by comparing specific keys: A guide

I have JSON data that contains a key called reportData with an array of values: {"reportData":[ ["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"], ["1186","R","5t","R","01","L","TP","00110","1854","2016" ...

Clicking the button will trigger the onclick event

I'm working on a button component in TypeScript and I have encountered an issue with passing the event to the submitButton function. import * as React from 'react'; interface Props { className?: string; text: string; onClick?(event: Reac ...

Analyzing Dynamic Content

Currently, I am engaged in content parsing and have successfully executed a sample program. To demonstrate, I have utilized a mock link which you can access below: Alternatively, you can click on this link: Click Here In the provided link, I have parsed ...

Introducing a fresh input field that includes a dropdown selection feature

When a user clicks on the "+" button, a new row should be added with a dropdown and input field. I want the input field name to be the dropdown value for each row. If "Facebook" is selected in the first dropdown, it should not appear in the second dropdo ...

The sluggish upload speed on Vimeo when using a library versus uploading directly

I have successfully integrated a library for uploading videos from my web app to Vimeo. Everything is working smoothly, but I am facing an issue with the upload speed. After running some tests, I noticed that the upload speed using the library is significa ...