🫢Mini Website with TypeScript, html, .d.ts, cấu hình nodemon.json (ok)

https://github.com/bobbyhadz/typescript-property-does-not-exist-on-type-window

package.json

{
  "name": "ts_browser_test___",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.12.5",
    "typescript": "^5.3.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "lib": [
      "es2016",
      "DOM"
    ],
    "module": "commonjs",
    "rootDir": "src",
    "sourceMap": true,
    "outDir": "build",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>bobbyhadz.com</title>
    <style>
      #container {
        background-color: lime;
        width: 450px;
        height: 450px;
      }
    </style>
  </head>
  <body>
    <div id="container">
      <h2>bobbyhadz.com</h2>
    </div>
    <script src="./src/index.ts"></script>
  </body>
</html>

src\index.ts

window.example = 'bobbyhadz.com';
console.log(window.example);

src\types\index.d.ts

export { };
declare global {
  interface Window {
    example: any;
  }
}

Last updated