![](/img/trans.png)
[英]Visual Studio Code Javascript Intellisense not working on event object properties
[英]Javascript Intellisense no longer working for object properties assigned after initial object creation in Visual Studio 2022
在 VS2022 中,與 VS2019 相比,Javascript Intellisense 服務似乎有一些重大修訂。
Javascript Intellisense 似乎不再識別在初始創建上下文之外分配的對象屬性。
var r = { a: 1, b: 2 };
r.c = 3;
//"r.a" and "r.b" will here be identified by Intellisense, but not "r.c".
當在 AngularJs 項目中存在范圍和依賴注入對象時,這是一些非常令人沮喪的行為,因為這些對象不再提供智能感知自動完成或使用“轉到定義”的導航。
這以前在 VS2019 中沒有JSDoc 標頭的情況下工作得很好。
a
, b
, c
, d
, e
在這里都可用。
這里只有a
、 b
、 d
可用。
是否有任何已知的設置或包來改變/糾正這種新行為?
發生這種情況是因為在 javascript 中您沒有類型聲明,並且因為您只聲明了兩個屬性,所以它假設您的對象只包含那些。 您可以通過添加注釋來避免這種情況,代碼/邏輯中沒有任何更改,但智能感知會識別它們
/** @type { {a: number, b: number, c?: number} } */
const obj = { a: 1, b: 2 };
// Now you can access every property your object has (not only the declared) and intellisense will recognize those declared
以同樣的方式,您可以聲明:
/** @type {string} */
const num = 12;
// Now intellisense will recognize it as a string even if it's a number
// and because in JS it's not an error to assign a number or a string to
// a variable it will throw an error at runtime if you try thing like
// num.trim();
確保您聲明的內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.