Is it necessary for 'ts-loader' to have 'typescript' installed in order to function properly? I personally did not encounter any issues with this

The npm documentation for using ts-loader suggests installing typescript. The official Typescript guide in webpack documentation also recommends the same, but without providing a clear explanation. However, I have successfully built everything without having typescript installed. What am I overlooking?

Here is my current setup:

webpack.config.js

const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    // mode: 'development',
    entry: './src/index.ts',
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: 'ts-loader'
            }
        ]
    },
    output: {
        filename: "bundle.js",
    },
    plugins: [
        new HtmlWebpackPlugin(),
        new webpack.ProgressPlugin()
    ]
}

package.json

{
  ...
  "scripts": {
    "webpack": "webpack",
    "build:dev": "npm run webpack -- --mode development",
    "start": "npm run webpack serve -- --mode development"
  },
  "author": "ranemihir",
  "license": "ISC",
  "devDependencies": {
    "html-webpack-plugin": "^5.5.3",
    "ts-loader": "^9.4.4",
    "webpack": "^5.88.2",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1"
  }
}

output:

asset bundle.js 1.3 KiB [compared for emit] (name: main)
asset index.html 233 bytes [compared for emit]
./src/index.ts 111 bytes [built] [code generated]
webpack 5.88.2 compiled successfully in 2099 ms

Answer №1

Upon inspection of their package.json, it's evident that typescript is designated as a peer dependency.

In the era before npm v7, handling peer dependencies required manual installation, leading to errors if your package didn't rely on TypeScript. With the introduction of npm v7, automatic installation of peer dependencies became the norm. Given that you are operating with npm version 7 or higher, TypeScript will now be installed seamlessly.

However, I would advise adding typescript to your project's dependencies. By doing so, ts-loader will consistently install the latest version of TypeScript (indicated by the "*"). This ensures that whenever TypeScript introduces significant changes in a new release, your project will automatically adapt. Thus, when someone revisits the project and executes npm install at a later time, there won't be any surprises jeopardizing the build process.

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

I'm currently working on creating an online store using Next.js and TypeScript, but I'm struggling to effectively incorporate my fake product data array into the site

"using client" import Container from "@/components/Container"; import ProductDetails from "./ProductDetails"; import ListRating from "./ListRating"; import { products } from "@/utils/products"; interface I ...

The Battle of Extends and Intersection in Typescript

Typescript's concept of extension is akin to C++'s inheritance. Intersection in Typescript involves creating a new object with all the properties from the intersected classes. Why utilize intersection when extends keyword can already merge ...

The FullCalendarModule does not have a property named 'registerPlugins' in its type definition

Currently in the process of integrating fullcalendar into my Angular 15 project and encountering the following error: Error: src/app/views/pages/takvim/takvim.module.ts:18:20 - error TS2339: Property 'registerPlugins' does not exist on type &apo ...

Prohibit the Use of Indexable Types in TypeScript

I have been trying to locate a tslint rule in the tslint.yml file that can identify and flag any usage of Indexable Types (such as { [key: string] : string }) in favor of TypeScript Records (e.g. Record<string, string>). However, I haven't had a ...

I'm having trouble grasping the issue: TypeError: Unable to access the 'subscribe' property of an undefined object

I've been working on a feature that involves fetching data from API calls. However, during testing, I encountered some errors even before setting up any actual test cases: TypeError: Cannot read property 'subscribe' of undefined at DataC ...

A custom Typescript type for immutable values within an object

I am struggling with finding the right data type for my function, where I need to work with static types. I have experimented with Type, interface, class, Record, and others, but none seem to fit perfectly. GEOLOCATIONS is a constant record that maps cou ...

VSCode highlights issues that do not impact the compilation process

While working in VSCode, I notice numerous issues with TypeScript syntax, but oddly enough, these problems do not impact the compilation process. It's puzzling to me why my colleagues are unable to see these issues like I do. Is there a way for me to ...

A step-by-step guide on generating a single chip using the same word in Angular

I'm trying to find a solution to ensure that only one chip is created from the same word inputted, instead of generating duplicates. Currently, users can input variations such as "apple," "APPLE," "apPPle," "aPpLe," and I want to automatically conver ...

Creating an object instance in Angular 2 using TypeScript

Looking for guidance on creating a new instance in TypeScript. I seem to have everything set up correctly, but encountering an issue. export class User implements IUser { public id: number; public username: string; public firstname: string; ...

Updating the FormControl value using the ControlValueAccessor

I have developed a directive specifically for case manipulation. The code I created successfully updates the visual value using _Renderer2, but I am facing an issue with formGroup.value. Even though the directive visually changes the value as expected, t ...

Restricting the data type of a parameter in a TypeScript function based on another parameter's value

interface INavigation { children: string[]; initial: string; } function navigation({ children, initial }: INavigation) { return null } I'm currently working on a function similar to the one above. My goal is to find a way to restrict the initi ...

How to transfer an object between sibling components in Angular 4

Being new to Angular 2+, I understand that I may not be approaching this the correct way. My issue involves two sibling components. When clicking on a "link" in one component, it redirects to another controller. My goal is to pass an object to the componen ...

Can anyone offer any suggestions for this issue with Angular? I've tried following a Mosh tutorial but it's

Just finished watching a video at around 1 hour and 35 minutes mark where they added the courses part. However, I encountered an error during compilation. ../src/app/app.component.html:2:1 - error NG8001: 'courses' is not recognized as an elemen ...

Maximizing Jest's potential with multiple presets in a single configuration file/setup

Currently, the project I am working on has Jest configured and testing is functioning correctly. Here is a glimpse of the existing jest.config.js file; const ignores = [...]; const coverageIgnores = [...]; module.exports = { roots: ['<rootDir&g ...

How come the Handsontable CSS styles are not being used on my Angular frontend?

I am currently facing an issue while trying to integrate a Handsontable into my Angular frontend. I was able to successfully implement the basic example from in a new Angular project. However, when I tried to add the exact same code to my existing reposit ...

Getting started with TypeScript and Azure CLI's 'az acr' command

Currently, I am in the process of developing a custom task for Azure DevOps Server 2019. While I have successfully created a .ps1 script for Windows, I am facing challenges with Linux. To tackle this, I have opted to write the script in TypeScript as I fin ...

How can I send parameters outside of the map function in ReactJS using Typescript?

Currently, I am receiving an array of objects from the Back End that has the following structure: const myArr = [ { A: "Ananas", B: "Banana", C: "Citroen" } ] My goal is to display a single JSX select me ...

Is it possible to utilize a const as both an object and a type within TypeScript?

In our code, we encountered a scenario where we had a class that needed to serve as both an object and an interface. The class had a cumbersome long name, so we decided to assign it to a constant. However, when we attempted to use this constant, we faced s ...

Keeping class secrets hidden?

This thought just crossed my mind, and I'm looking for a way to make classes private in TypeScript. Let me explain the situation: Inside my directory Typescript/circle/circle.ts, I have the following code snippet: class Circle { PI:number = 3.14; ...

Material UI TreeView: Organize and present node data with multiple columns in a tree structure

const treeItems = [ { id: 1, name: 'English', country: 'US', children: [ { id: 4, name: 'Spring', country: 'Uk', ...