且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jshint/PhpStorm:“未解析的变量"当使用jquery .data()时

更新时间:2022-02-14 00:06:26

根据 JSDoc文档正确的方法应该使用@typedef定义实际的对象结构(特别是有用的,如果以后将在另一个地方重用它),并且使用@type声明特定变量的类型:

Accordingly to JSDoc docs the proper way should using @typedef to define actual object structure (especially useful if it will be re-used later in another place) and @type to declare type of particular variable:

/**
 * @typedef {Object} MyInputData
 * @property {string} connectto 
 * @property {string} othervalue
 */

/** @type {MyInputData} */
var input = inputObj.data();

这个(只有@typedef并且变量名作为类型名)似乎也可以在PhpStorm中使用:

This one (with just @typedef and variable name as type name) seems to work in PhpStorm as well:

/**
 * @typedef {Object} input
 * @property {string} connectto 
 * @property {string} othervalue
 */
var input = inputObj.data();