简体   繁体   English

如何在javascript中为Closure Compiler注释嵌套对象,并且所有属性都是可选的?

[英]How to annotate nested object in javascript for Closure Compiler and have all properties optional?

Here is my class A and I want all options to be optional. 这是我的A级,我希望所有选项都是可选的。 It works fine for a,b,c properties but it doesn't work for c.cX properties. 它适用于a,b,c属性,但它不适用于c.cX属性。 How to do it properly to make all properties optional? 如何正确地使所有属性可选?

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==

/**
 * @typedef {{
 *     a: (string|undefined),
 *     b: (number|undefined),
 *     c: ({
 *         ca: (string|undefined),
 *         cb: (number|undefined),
 *         cc: (Function|undefined)
 *     }|undefined)
 * }}
 */
var Options;


/**
 * @param {Options=} options
 * @constructor
 */
var A = function(options) {
    console.log(this);
};


new A({
    a: 'x',
    c: {
        ca: 'x',
        //cb: 1,
        cc: function() {}
    }
});

Options type should be defined like this: Options类型应该像这样定义:

/**
 * @record
 * @struct
 */
function Options() {};

/** @type {string|undefined} */
Options.prototype.a;

/** @type {number|undefined} */
Options.prototype.b;

/** @type {!OptionsC|undefined} */
Options.prototype.c;


/**
 * @record
 * @struct
 */
function OptionsC() {};

/** @type {string|undefined} */
OptionsC.prototype.ca;

/** @type {number|undefined} */
OptionsC.prototype.cb;

/** @type {Function|undefined} */
OptionsC.prototype.cc;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Google Closure Compiler 注释可选参数? - How to annotate an optional parameter using Google Closure Compiler? 闭包编译器:如何将对象及其所有属性声明为extern? - Closure compiler: How to declare object and all of its properties as extern? 如何使用闭包编译器在javascript中注释扩展泛型类的类 - How to annotate in javascript a class that extends a generic type, using closure compiler 如何在javascript中扩展抽象类并为闭包编译器添加注释,但没有闭包库? - How do you extend an abstract class in javascript and annotate for closure compiler but without closure library? 在JavaScript中为Google Closure编译器注释Singleton对象,或“危险使用全局此对象”警告 - Annotate Singleton objects in JavaScript for the Google Closure Compiler, or “dangerous use of the global this object” warning 如何获取闭包编译器以正确检查JavaScript中构造函数的属性 - How to get closure compiler to properly check the properties of a constructor in javascript 是否可以为闭包编译器添加@language ECMASCRIPT5来注释JavaScript? - Is it possible to annotate JavaScript for the Closure Compiler adding @language ECMASCRIPT5? JavaScript将所有嵌套对象属性设置为null - JavaScript set all nested object properties to null 如何在 JSDoc 中使用可选属性注释匿名对象 - How to annotate anonymous object with optional property in JSDoc 如何使用Google Closure编译器声明动态属性? - How to declare dynamic properties with Google Closure Compiler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM