Alex Craft
Alex Craft

Reputation: 15336

Can Deno bundle TypeScript into JavaScript for Browser?

I tried to bundle TypeScript with Deno, but it seems like it doesn't have the browser types.

I would like to use Deno as a simple option instead of WebPack etc.

console.log(window.document)
deno bundle browser/play.ts

Error

error: TS2339 [ERROR]: Property 'document' does not exist on type 'Window & typeof globalThis'.
console.log(window.document)

Upvotes: 0

Views: 593

Answers (2)

goddtriffin
goddtriffin

Reputation: 145

These are the compiler options I use to target the browser:

{
    "compilerOptions": {
        "lib": [
            "dom",
            "dom.iterable",
            "dom.asynciterable",
            "deno.ns"
        ]
    },
}

Upvotes: 1

Alex Craft
Alex Craft

Reputation: 15336

The following tsconfig.json option needed to be added to Deno (and also added to VSCode deno config).

{
  "compilerOptions": {
    "lib": ["dom", "deno.ns"]
  }
}

Upvotes: 2

Related Questions