node.js - 运行空白 typescript 项目

标签 node.js html typescript npm

我想运行一个包含 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/

相关文章:

typescript - 类型断言与属性

Node.js 将 GET 值传递给 socket.io?

html - php mail 添加随机空格和 float 元素

html - 具有背景大小的 DIV

jquery - Bootstrap 动态模式中的 Previous Next 按钮

angular - "Maximum call stack size exceeded"在 Angular 9 ng build --prod 中用于库

javascript - 为什么在 TypeScript 中使用三等号 (===)?

javascript - 还可以发送图像甚至文件的 Socket.io 聊天应用程序

node.js - 在 jest 拆解中杀死一个 Node.js 服务器(在 jest 的安装钩子(Hook)中启动)

javascript - 返回 Mongoose 模型函数的结果