Using TypeScript and its import feature with file extensions

Have you heard about the latest Deno, a TypeScript runtime?

An important distinction between Deno and traditional TypeScript is that the file extension must be included in the import statement. For example:

import foo from './bar.ts'
                       ^^

I am interested in writing code that can work with both Deno and Webpack.

How can I configure Webpack to allow imports with the .ts extension like shown above?

Additionally, how can I resolve the following error in VSCode?

https://i.sstatic.net/rKyYS.png

Answer №1

Webpack has the capability to resolve import extensions by configuring the resolve property. By including an empty string in the list of extensions, webpack will accept imports with full extensions as well, with the empty string being the first entry in the list.

module.exports = {
 // ...
 resolve: {
   extensions: ['', '.ts', '.tsx' /*etc ...*/],
 }
}

If the list of extensions does not include an empty string, webpack may attempt to import something like ./bar.ts.ts instead of ./bar.ts.

To disable warnings in VSCode from the ts-compiler, you can use a comment like this:

// @ts-ignore TS6133
import foo from './bar.ts'

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

Bring in jspm libraries to your project via typescript

While researching how to import jspm packages into typescript, I noticed that most examples assumed the use of SystemJS for loading and interpreting them in the browser. However, I prefer using tsc to compile commonjs modules and only import the js code, a ...

Navigating typescript declarations using eval

Struggling to create a precise definition file for the webworker-threads npm library. According to their documentation, a new worker can be created in the following manner: let worker = new Worker(function() { this.postMessage('worker created' ...

Using Angular 2 to create an Observable type that mediates two separate http.get calls

In my ng2 service, I have a method that contains two http.get calls. Here is an example of the function: getInfo(userId: number): any { this.http .get(apiUrl, options) .map(response => response.json()) .subscribe(example => ...

"Introducing a brand new column in ng2-smart-table that is generated from an Object

Can anyone provide guidance on how to create a new column from an Object datatype? I'm struggling with this task. Below are the settings and data for better clarity: private settings = { columns: { firstName: { title: &apo ...

What is the best way to manage errors in a stream while avoiding additional processing?

Consider the following situation: this.http.call().pipe( catchError((error) => { takeAction(); }), switchMap((data) => { performAdditionalTasks(); }), ); Is it feasible for the switchMap function to be skipped or not ...

Creating a singleton in TypeScriptWould you like to know how to declare a singleton in

My goal is to incorporate an already existing library into my TypeScript project. The library contains a singleton object that I want to declare and utilize. For example, within the xyz.js file, the following object is defined: var mxUtils = { /* som ...

Component using ControlValueAccessor failing to update value within formgroup in Angular 7

I am currently working with Angular 7 and have created a child component using 'ControlValueAccessor'. Within this component, I have included a combobox and textbox in my form. The issue I am facing is that when I select an item from the combobox ...

Issue with Angular Material Mat Horizontal Stepper: Incorrect step selection when progressing with next button

I have a horizontal mat stepper that needs to be controlled using Next and Back buttons. The steps are generated using ngFor. I have created a variable called "stepIndex" which is bound to the "selectedIndex" input. The Next button should increment this va ...

What is the best approach for managing errors within a shared observable in TypeScript?

I'm facing a unique issue and struggling to find someone who has encountered the same problem, which could imply that I am approaching it incorrectly. The http request I am making looks like this: return this.httpClient.post(`${this.route}/typegroups ...

The datepicker is functioning correctly, however, the displayed value does not reflect the updated date

The version of angularjs being used is 1.5.11. Within my .NET MVC project, the bs-datepicker element from angularjs is incorporated. Featured below is the datepicker component accompanied by a pair of images functioning as buttons within my application: & ...

Guide to uploading audio files using express backend and react-native technology

Having trouble uploading audio files in my react-native project because it appears there is no FileList in react-native. Any assistance would be greatly appreciated. Thanks~ interface IAudioInputs { readers_id: number; level_type_id?: number; books ...

How to populate a form array in Angular

I am currently working with Angular 8 and have an API structured like this: { "no": "s01", "id": 1, "details_id": { "install": "Y" "unitprice": "100.00 ...

What is the best way to link a table header to a row cell click event in an HTML table

Is there a way to retrieve the table header of a specific row cell when a checkbox in that row cell is clicked? I want it to return only the header where the clicked cell is located. Here's an example of what I'm trying to achieve: https://stackb ...

Encountering a build issue while attempting to upgrade to the newest version of Angular Slick

After upgrading from angular slickgrid version 2.19.0 to the latest version 2.29.1, I encountered a build issue (ng build). Attached is a screenshot of the error: https://i.sstatic.net/7OUX1.png Software versions: Angular: 7.3.5 TypeScript: 3.1.6 Node: ...

Ways to update a child's state without triggering a re-render of the parent component

Is there a way to update the content of a child component based on a user interaction in another child component without triggering a re-render of the parent component? I attempted to store the child state setter in a variable within the parent component, ...

Is it possible to create a distinctive property value within an ngFor loop that operates autonomously across two child components?

I am working on a functionality where, upon clicking on a specific car brand, the name of the person and their favorite car will be displayed at the bottom. However, I'm facing an issue where the car brand is being repeated among all items in the ngFo ...

declaration of function interface and property that cannot be modified

After reviewing some new TypeScript code, I encountered a part that left me puzzled. interface test { (a: number): number; readonly b: number; } While I understand that (a:number): number signifies a function where the argument is a:number and the ret ...

Guide on crafting Mongoose query for MongoDB

In my system, I have defined two document schemas: User and Skill. Each User has a list of skills referenced in the skills attribute. Conversely, each Skill has a list of users who possess that skill referenced in the users attribute. The main goal is t ...

How does the nonempty assertion of TS impact the inference of function generics?

My definition of the type and the variable is as follows: the LOCALES_KEYS variable is an enum export const resources = { 'ja-JP': jaJP, 'zh-TW': zhTW, 'en-US': enUS, 'zh-CN': zhCN, }; export type Lng = key ...

Relocating to new pages as WebSocket connection terminates and then reconnects

Currently working on a React project with Vite, encountering an issue where the websocket connection closes and re-establishes when navigating to another page using the sidebar. Main.tsx :- import ReactDOM from 'react-dom/client'; import App fro ...