我想运行一个包含 package.json、typescript 和 html 文件的空白 typescript 项目。- 类似于 Stackblitz Blank-typescript project 。 任何人都可以为我提供一步一步的指导,如何设置这样的项目。我目前正在使用 Webstorm 作为 IDE,如果了解这一点很重要的话。
提前谢谢您!
最佳答案
我想我有我的解决方案。
步骤 1
使用 npm install typescript --save
在您的项目上安装 typescript
步骤2
创建一个 tsconfig 文件以使用 tsc --init
为您的项目应用 typescript 规则
步骤 3
创建index.ts和index.html文件
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Promises vs. Observables</title>
</head>
<body>
<div id="app">
<script src="index.js"></script>
</div>
</body>
</html>
index.ts:
const world = '🗺️';
const appDiv: HTMLElement | null = document.getElementById('app');
if (appDiv) {
appDiv.innerHTML = `<h1>Hello ${world}</h1>`;
console.log(`hello ${world}`);
}
最后一步
使用tsc -w
在监视模式下编译
项目正在运行!如果我可以在我的解决方案上做一些更好的事情,请随时告诉我!
关于node.js - 运行空白 typescript 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52165250/