How to use typescript in browser?

后端 未结 4 590
無奈伤痛
無奈伤痛 2020-12-31 04:21

utility.ts

let books = [
    { id: 1, title: \"the dark window\", author: \"krishna\", available: true },
    { id: 2, title: \"naked eye\", author: \"sydney         


        
4条回答
  •  悲哀的现实
    2020-12-31 05:18

    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

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

    See it altogether at : https://github.com/SalathielGenese/ts-web

    Disclosure : I'm its author.

提交回复
热议问题