I'm a beginner in TypeScript and wrote the following code in MVC5 application:
Controller:
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
}
View:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/app.js"></script>
</head>
<body>
<div id="cont"></div>
</div>
</body>
</html>
TypeScript:
class MyClass {
public render(divId: string, text: string) {
var el: HTMLElement = document.getElementById(divId);
el.innerText = text;
}
}
window.onload = () => {
var MyClass = new MyClass();
MyClass.render("cont", "Hello World");
};
tsconfig.json:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"outDir": "../Scripts"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
I've got the following error:
TypeError: MyClass is not a constructor.
How can I run my first TypeScript?