且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在浏览器中使用打字稿?

更新时间:2022-12-13 21:28:52

  1. 将浏览器更新到最近的浏览器(最近足以支持 ES2015 模块)
  2. tsconfig.json target 更改为 es2015
  3. tsconfig.json module 更改为 es2015
  4. 始终在导入语句中添加 .js 扩展名
  5. 使用像 live-server 这样的 http 服务器来避免使用 file://协议的 CORS 问题
  1. Update browser to recent one (recent enough to support ES2015 module)
  2. Change tsconfig.json target to es2015
  3. Change tsconfig.json module to es2015
  4. Always add .js extension to your import statements
  5. Use an http server like live-server to avoir CORS concerns with file:// protocol

奖励:tsconfig.json moduleResolution 显式设置为 node.如果您不使用外部库或 @types/* 包,则不需要这样做.

BONUS: Explicitly set tsconfig.json moduleResolution to node. This is not necessary if you don’t use external libraries or @types/* packages.

在以下位置完全查看:https://github.com/SalathielGenese/ts-web

披露:我是它的作者.