簡體   English   中英

TypeScript錯誤:Visual Studio中“找不到名稱”

[英]TypeScript error: “Cannot find name” in Visual Studio

我已經看到了很多有關此主題的話題和討論,但是我沒有解決此問題。 這是我幾天前的帖子

其中一個目的的typings是要避免使用的<reference>標簽,是嗎?

但是,如果我不使用它,Visual Studio會抱怨:

在此處輸入圖片說明

一旦我引用browser.d.ts Visual Studio就會停止抱怨。

這是我的tsconfig

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "files": [

  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

我還嘗試按照此處的建議從tsconfig刪除"files"屬性,但是如果執行此操作,則會在打字環境文件夾中的其他打字稿文件中出現編譯錯誤。

代碼可以運行,並且一切都很好,但是我想了解我是在做錯什么還是Visual Studio問題。

對於將來可能遇到相同問題的人:

我解決了這個問題。 秘密是從tsconfig排除"files"屬性,並在"excluded"部分中添加文件夾"typings"

tsconfig現在應如下所示:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "exclude": [
    "typings",
    "node_modules",
    "wwwroot"
  ]
}

就我而言,我修復了在tsconfig.json "types"部分中添加"jasmine" tsconfig.json 像這樣:

{
    "compilerOptions": {
      "noImplicitAny": false,
      "noEmitOnError": true,
      "removeComments": false,
      "sourceMap": true,
      "target": "es5"
    },
    "exclude": [
      "typings",
      "node_modules",
      "wwwroot"
    ],
    "types": ["jasmine"]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM