Search code examples
javascriptdomtypescript

Is TypeScript's purpose to be used for manipulating the DOM like JavaScript is?


Every TypeScript example and tutorial I have found thus far is about language features, Static typing, Visual Studio, etc. I cannot find anything to tell me how I should be using it with reference to JavaScript and the DOM.

My understanding it you can use TypeScript for the DOM. But, I never see anyone using it for that. I have a set of JavaScript IIFE objects, and I want to convert them, but as these manipulate the DOM, I'm not sure what part TypeScript plays here.

As it concerns manipulating the DOM, should I be using TypeScript for this? Not can I. Is it expected that I should, given I am using TypeScript in a new Web Application Project.

I do not know this answers it, What is TypeScript and why would I use it in place of JavaScript?

Edit: I understand what TypeScript is and does. My question is more why don't I see more people using it for the DOM? Is it not supposed to be used that way with the DOM, even though it can be used that way?


Solution

  • TypeScript can be used for anything JavaScript can be used for. It's JavaScript plus a layer of type information (and usually adopts newer JavaScript features fairly quickly), which is then compiled to JavaScript for deployment and use in the wild.

    When using TypeScript to manipulate the DOM, you'll need type information for the DOM; see this question and its answers for more about getting DOM type information into your project.