fix(array-tracer): 修正创建命令中数组参数的必填性
将 `ArrayTracerCreateCommand.params.array` 从可选参数改为必填参数,以匹配实际实现逻辑。 同时更新 `createArrayTracer` 函数,确保在未提供 `array` 时使用空数组作为默认值,保持向后兼容性。
This commit is contained in:
@@ -9,7 +9,7 @@ interface ArrayTracerCreateOptions<T extends JsonValue[]> {
|
||||
export const createArrayTracer = <T extends JsonValue[]>(
|
||||
options: ArrayTracerCreateOptions<T>,
|
||||
) => {
|
||||
const { description = 'ArrayTracer', array } = options;
|
||||
const { description, array } = options;
|
||||
const tracer = crypto.randomUUID();
|
||||
|
||||
// 优化:仅维护数组长度作为影子状态,这在 C++/Java 等强类型语言中也极易实现(仅需一个 int 变量)
|
||||
@@ -31,8 +31,8 @@ export const createArrayTracer = <T extends JsonValue[]>(
|
||||
tracer: tracer,
|
||||
action: 'create',
|
||||
params: {
|
||||
description: description,
|
||||
array: array,
|
||||
description: description ?? 'ArrayTracer',
|
||||
array: array ?? [],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ type ArrayTracerCreateCommand = BaseArrayTracerCommand & {
|
||||
action: 'create';
|
||||
params: {
|
||||
description: string;
|
||||
array?: JsonValue[];
|
||||
array: JsonValue[];
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user