What are the steps to effectively troubleshoot TypeScript code in Visual Studio 2017?

Currently working on an ASP.NET Core project that heavily utilizes TypeScript.

Does Visual Studio support debugging TypeScript code?

Answer №1

In the past, Visual Studio did not offer this functionality.

However, with the release of Visual Studio 2017, this issue has been resolved. Simply set your breakpoint, run your project using IE or Chrome, and your breakpoint will be triggered in your TypeScript file within the VS environment (not in the browser's code debug window). This advancement is a significant improvement for Typescript development.

An interesting feature is that if the code transitions to JavaScript when moving to another file without a corresponding TypeScript file, it will seamlessly switch back to TypeScript when possible.

Answer №2

Ensure that browser link is enabled to view TS breakpoints being triggered. You can find the option as a blue arrow circle located on the right side of the browser selection drop-down menu in VS2017, as it may be disabled by default.

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

Answer №3

While working on converting the dotnetcore ReactRedux template to Typescript, I encountered an issue where breakpoints were not hitting my typescript files.

After some investigation, I discovered that in the tsconfig.json file, it is necessary to have the options inlineSourceMap:true and inlineSources:true set in order for breakpoints to work correctly.

Answer №4

One of the easiest ways to debug JavaScript and TypeScript is by utilizing the Microsoft Edge DevTools Protocol, which was introduced with the Windows 10 April 2018 Update (Version 1803). Additionally, you'll need Visual Studio 2017 Version 15.7 or a newer version.

In the past, I struggled with getting JavaScript debugging to function properly. However, thanks to these updates, it now works seamlessly:

  • Simply initiate debugging for your ASP.NET project
  • Add breakpoints in your TypeScript (or JavaScript) files
  • If JavaScript debugging isn't enabled, a prompt will appear suggesting enabling it. You can also access this option in VS settings: Tools > Options > Debugging > General > Enable JavaScript debugging for ASP.NET (Chrome, Edge, and IE)
  • No need to restart; breakpoints are activated instantly

Note that when using Edge, there will be an indication that the developer tools server has been launched:

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

Answer №5

I discovered two scenarios that do not cause issues in Visual Studio 2017 (version 15.9.5).

1) .UseContentRoot
When modifying the content route using UseContentRoot() in the WebHost.CreateDefaultBuilder method in Program.cs, Visual Studio will not encounter any errors.

2) wwwroot Folder
Changing the webroot with UseWebRoot() functions correctly.
However, even if "wwwroot" folder is deleted from the project root, Visual Studio will still run without any issues.

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

What's the best way to determine the event type when a mouseDown occurs in React while working on a canvas?

I've been tackling the challenge of incorporating the <canvas /> element into a react project, but I'm encountering difficulties with determining the appropriate event type for it. In my quest for answers, I stumbled upon this insightful ar ...

Having trouble importing Bootstrap CSS into a TypeScript file

I'm having trouble importing the bootstrap css file from node_modules. It's not importing, even though I can import the scss file successfully. The following import is not working: import bs from "bootstrap/dist/css/bootstrap.css"; Ho ...

synchronize the exchange of information and events between two components

Just joined this platform and diving into Angular 7 coding, but already facing an issue. I've set up two components along with a service. The data is fetched by the service upon clicking a button in the searchbar component, and I aim to display it i ...

Is Typescript compatible with the AWS Amplify Express API?

I've been struggling to set up my Amplify API in TypeScript and then transpile it to JavaScript. I know it sounds like a simple process, but I could really use some guidance on how to do this effectively. So far, I haven't progressed beyond the ...

What is the best way to convert the reader.result into a string?

Whenever I attempt to upload an image on Angular, I encounter an error with reader.result in the TypeScript file below. How can I resolve this issue? I even included console.log(image) in the onImagePicked function but it doesn't display anything in ...

Uncertainty surrounding the combination of observables due to their varying outcomes

Currently, I am developing an angular2 application that implements the ngrx store approach for state management. The source code for the app is available on github here The Issue at Hand The specific challenge I am encountering with this method involves ...

Navigating with Angular: Transmitting dynamic URL parameters to components

I currently have the following routes defined: const routes: Routes = [ { path: ':product/new', children: [{ path: 'std/:country', component: SignUpComponent, data: { ...

Unable to locate the module 'next' or its associated type declarations

Encountering the error message Cannot find module '' or its corresponding type declarations. when trying to import modules in a Next.js project. This issue occurs with every single import. View Preview Yarn version: 3.1.0-rc.2 Next version: 1 ...

Creating a React prop type validation that is dependent on the value of another prop

I am in the process of creating a custom React Table component, with the following TableProps structure: export interface ColumnType<ItemType, Key extends keyof ItemType = keyof ItemType> { header: string; key?: keyof ItemType; renderCell: (val ...

Dynamic Angular Menu

Is there a cleaner, more dynamic way to implement a mat menu with individual click values and disable properties for each button? I want to avoid repeating code like in the example below. Looking for a more dynamic solution. #code <mat-menu #createDeal ...

Creating a read-only DIV using Angular - a step-by-step guide

Is there a simple way to make all clickable elements inside a div read only? For example, in the provided HTML code, these divs act like buttons and I want to disable them from being clicked. Any tips or shortcuts to achieve this? Thank you. #html < ...

Using Partial function input in TypeScript

I am in need of a function that can accept partial input. The function includes a variable called style, which should only have values of outline or fill, like so: export type TrafficSignalStyle = 'outline' | 'fill' let style: TrafficSi ...

What is the method for utilizing an alias at the top within a subquery?

Is it possible to use an alias from the top query in a subquery? I am currently encountering an error with 'artc'. let myQuery = this.articles.createQueryBuilder('artc') .select(['artc.title']) .addSelect(qb => ...

The function Observable.timer in Angular rxjs is throwing an error when imported

Encountering an error in my Angular application that reads: ERROR TypeError: rxjs_Observable__WEBPACK_IMPORTED_MODULE_4__.Observable.timer is not a function at SwitchMapSubscriber.project (hybrid.effect.ts:20) at SwitchMapSubscriber.push ...

Mastering Angular 2 Reactive Forms: Efficiently Binding Entire Objects in a Single Stroke

Exploring reactive forms in Angular 2 has led me to ponder the possibility of binding all object properties simultaneously. Most tutorials show the following approach: this.form = this.fb.group({ name: ['', Validators.required], event: t ...

Angular2 checkboxes for filtering data

I'm working with an Angular2 grid that showcases an array of Fabrics, each with its own color or fabric type properties. Right now, all Fabrics are displayed in the grid, but I need to implement a series of checkboxes for color and fabric type, along ...

What is the best approach for incorporating a customized set of valid keywords into a text input field in JHipster while maintaining a sophisticated design?

My code snippet is not displaying the input even though all the necessary elements are in place: home.component.ts <p class="lead">Input: </p> <div><jhi-calculator-input></jhi-calculator-input></div> calculator.compon ...

Disappearing act: Ionic tabs mysteriously disappear when the back button

Whenever I navigate in my ionic app, I notice that the tabs-bar disappears when I go to different pages and then return to the tabs. See Demo Code tab1 Here is a sample link to navigate to other pages: <ion-label routerDirection="forward" [routerLi ...

When a Vue component collapses on itself, it prevents the next component from rendering

Within my primary component, known as App.vue, I have structured the template code like so: <template> <div class="app-wrapper"> <Header></Header> <Panel></Panel> <Showcase/> <Modal/> < ...

What is the reason behind the NgForOf directive in Angular not supporting union types?

Within my component, I have defined a property array as follows: array: number[] | string[] = ['1', '2']; In the template, I am using ngFor to iterate over the elements of this array: <div *ngFor="let element of array"> ...