首页 > 解决方案 > 运行空白打字稿项目

问题描述

我想运行一个带有 package.json、typescript 和 html 文件的空白 typescript 项目。-类似于 Stackblitz blank-typescript项目。任何人都可以为我提供一步一步的指导,如何设置这样的项目。如果知道这一点很重要,我目前正在使用 Webstorm 作为 IDE。

先感谢您!

标签: node.jshtmltypescriptnpm

解决方案


我想我有我的解决方案。

步骤1

在您的项目上安装打字稿npm install typescript --save

第2步

创建一个 tsconfig 文件来为您的项目应用打字稿规则tsc --init

第 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>

索引.ts:

const world = '️';

const appDiv: HTMLElement | null = document.getElementById('app');

if (appDiv) {
    appDiv.innerHTML = `<h1>Hello ${world}</h1>`;
    console.log(`hello ${world}`);
}

最后一步

在监视模式下编译tsc -w

项目正在运行!如果我可以在我的解决方案上做得更好,请不要犹豫告诉我!


推荐阅读