Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 高级JSDoc(类型脚本)_Javascript_Jsdoc - Fatal编程技术网

Javascript 高级JSDoc(类型脚本)

Javascript 高级JSDoc(类型脚本),javascript,jsdoc,Javascript,Jsdoc,主要问题:我需要用具体的对象结构扩展任何对象结构。 我在VS代码中测试的默认值 我的解决方案建议: /** @template A @typedef {{[Ki in keyof A]: A[Ki] } & {[k: string]: {} } & A} Deep3 */ /** @template A @typedef {{[Ki in keyof A]: Deep3<A[Ki]>} & {[k: string]: Deep3<

主要问题:我需要用具体的对象结构扩展任何对象结构。

我在VS代码中测试的默认值

我的解决方案建议:

/** @template A @typedef {{[Ki in keyof A]:       A[Ki] } & {[k: string]:       {} } & A} Deep3 */
/** @template A @typedef {{[Ki in keyof A]: Deep3<A[Ki]>} & {[k: string]: Deep3<{}>} & A} Deep2 */
/** @template A @typedef {{[Ki in keyof A]: Deep2<A[Ki]>} & {[k: string]: Deep2<{}>} & A} Deep */

/** @type {Deep<{a: {b: number}}>} */
let x = {a: {b: 9, c: {d: 8}}};     // ERROR: Type 'number' is not assignable to type '{ [k: string]: {}; }'
x.a.c.d = 9;    // OK
/** @type {Number & {[k: string]: Number}} */
let a = 9;          // ERROR: Type '11' is not assignable to type '{ [k: string]: { x: number; }; }'
a.optional = 9;     // OK

/** @type {Number | {[k: string]: Number}} */
let b = 9;          // OK
b.optional = 9;     // ERROR: Property 'optional' does not exist on type 'number'
b = 4;
此处不存在此问题:

/** @type {Number & {optional?: Number}} */
let c = 9;          // OK
c.optional = 9;     // OK

在TypeScript中,行为等于。

您的代码帮助我找到解决问题的方法。 不确定我们是否有相同的问题,但这里是我的代码。 基本上添加了
部分
为我删除可分配的警报!:)

/**@type{Partial}*/