8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Typescriptでグローバル変数(window.○○)

Posted at

プロジェクトフォルダの中に@typesというディレクトリを作成し、
その中にglobal.d.tsというファイルを作成します。

####中身

global.d.ts

import firebase from "firebase/app";//例

declare global {
    interface Window{
        firebaseApp: firebase.app.App//例
//この中に好きに定義する
    }
}

interface Window の中に含めたい変数をいれてから
window.○○のように使います。

####できない場合
tsconfig.jsonのfilesにglobal.d.tsを入れてください。

tsconfig.json
{
    "省略":"",
    "files": [
        "@types/global.d.ts"
    ],
    "省略":""
}

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?