Webstorm에서 경고하는 수많은 미해결 변수와 싸우는 방법은 무엇입니까?
서버에서 데이터를 가져 오는 함수가 있습니다.
function getData(data){
console.log(data.someVar);
}
Webstorm은 someVar
-가 해결되지 않은 변수 라고 말합니다 . 그러한 경고를 어떻게 제거 할 수 있습니까?
몇 가지 옵션이 있습니다.
- ide 설정에서 경고를 억제합니다.
- 필드 ( details )가 있는 json 소스 파일을 추가하십시오 .
- 배열과 유사한 구문 사용 :
data['some_unres_var']
;
또한 Webstorm은 "데이터"(와 같은 주석 추가)에 대한 네임 스페이스를 /** @namespace data.some_unres_var*/
생성하거나, 이러한 필드를 생성하거나, 이름을 변경하도록 제안 합니다.
JSDoc 사용 :
/**
* @param {{some_unres_var:string}} data
*/
function getData(data){
console.log(data.some_unres_var);
}
JSDoc 개체. 그런 다음 그 구성원.
/**
* @param data Information about the object.
* @param data.member Information about the object's members.
*/
function getData(data){
console.log(data.member);
}
@property
지역 변수 (매개 변수가 아님)- PyCharm에서 테스트되었습니다. @Nicholi는 Webstorm에서 작동하는지 확인합니다.
{{ member:type }}
구문 안드레아스 장고 템플릿과 충돌 할 수 있습니다 제안했다.- @param wiki를 인용 한 Jonny Buchanan의 답변 덕분 입니다 .
객체 배열 을 문서화하려면 []
JSDoc이 제안하는 대로 대괄호를 사용하십시오 .
/**
* @param data
* @param data.array_member[].foo
*/
다른 모든 답변은 일반적인 경우에 올바르지 않습니다. data
매개 변수로 가져 오지 않으면 어떻게 됩니까? 그러면 JSDoc이 없습니다.
function niceApiCall(parameters) {
const result = await ... // HTTP call to the API here
for (const e of result.entries) {
.. // decorate each entry in the result
}
return result;
}
WebStorm은 "result.entries"가 확인되지 않은 변수 (필드)임을 경고합니다.
일반적인 해결책은 @namespace
선언 을 추가하는 것입니다 .
function niceApiCall(parameters) {
/** @namespace result.entries **/
const result = await ... // HTTP call to the API here
for (const e of result.entries) {
.. // decorate each entry in the result
}
return result;
}
using a dummy js file with anonymous function expression returning the json literal, as written at http://devnet.jetbrains.com/message/5366907, may be a solution. I can also suggest creating a fake variable that will hold this json value, and use this var as a value of @param annotation to let WebStorm know what the actual type is. Like:
var jsontext = {"some_unres_var":"val"};
/** @param {jsontext} data
function getData(data){
console.log(data.some_unres_var);
}
See also http://devnet.jetbrains.com/message/5504337#5504337
Destructuring use, Luke.
function getData(data){
const {member} = data;
console.log(member);
}
'developer tip' 카테고리의 다른 글
Java 코드 온라인 실행 (0) | 2020.08.15 |
---|---|
C #의 StringBuilder와 같은 Python 문자열 클래스? (0) | 2020.08.15 |
Java 클래스가 구현 된 인터페이스에서 주석을 상속하지 않는 이유는 무엇입니까? (0) | 2020.08.15 |
PHP는 두 개의 다른 문자열을 동일하게 표현합니다. (0) | 2020.08.15 |
부모 div 내부에 수평으로 div를 중앙에 배치하는 방법 (0) | 2020.08.15 |