Recordable<T = any, K = string> = Record<K extends null | undefined ? string : K, T>
时间: 2024-02-27 10:56:16 浏览: 153
这是一个 TypeScript 中的类型别名,它定义了一个泛型 Recordable 类型。Recordable 类型是一个对象类型,其中的属性名为 K 类型的属性名,属性值为 T 类型的属性值。
如果 K 类型为 null 或 undefined,则属性名为 string 类型。
例如,如果我们使用 Recordable<number, "foo" | "bar">,则生成的类型为:
```
{
foo: number;
bar: number;
}
```
相关问题
// 获取表单值 const form = getFieldsValue(); // 条件值的component类型会随着字段的变化发生变化 // 条件值发生变化时获取当前字段列详细数据 const currentFieldData = columnOptions.value.find( (item: Recordable) => item.value === form.field, ) as unknown as Recordable; // 根据字段label const fieldLabel = columnOptions.value.find((item) => item.value === form?.field)?.label; // 判断条件 const conditionType = ARITHMETIC_OPERATOR_BACK.find( (item) => item.value === form?.op, )?.operate; if (form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL) { // 判断条件为空、非空时,清空条件值 conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}; } else { // 字段值和判断条件发生变化 let labelText; // 字段变化 if (key === 'field') { if (currentFieldData?.component !== FormElementEnum.SWITCH) { // 清空条件值 await setFieldsValue({ value: undefined }); labelText = ''; } else { await setFieldsValue({ value: 0 }); labelText = '否'; } } else { // 判断条件和条件值变化 // 当前字段有值集时,component类型为ApiSelect if (currentFieldData?.component === FormElementEnum.API_SELECT) { const fieldVsList = await getVsList(currentFieldData.vsId); labelText = fieldVsList?.find( (item: Recordable) => item.itemValue === form.value, )?.itemText; } else if (currentFieldData?.component === FormElementEnum.SWITCH) { // 当前字段类型为boolean时,component类型为Switch,条件值为开关 labelText = form.value === 1 ? '是' : '否'; } else { // 其他 labelText = form.value; } } conditionName = ${fieldLabel ?? ''}${conditionType ?? ''}${labelText ?? ''}; }简化if语句
可以将 if-else 语句简化为三目运算符,如下所示:
```
conditionName = form.op === ConditionTypeEnum.IS_NULL || form.op === ConditionTypeEnum.IS_NOT_NULL
? `${fieldLabel ?? ''}${conditionType ?? ''}`
: key === 'field'
? currentFieldData?.component !== FormElementEnum.SWITCH
? (await setFieldsValue({ value: undefined }), '')
: (await setFieldsValue({ value: 0 }), '否')
: currentFieldData?.component === FormElementEnum.API_SELECT
? ((await getVsList(currentFieldData.vsId)), labelText = fieldVsList?.find((item: Recordable) => item.itemValue === form.value)?.itemText)
: currentFieldData?.component === FormElementEnum.SWITCH
? (labelText = form.value === 1 ? '是' : '否')
: (labelText = form.value, '');
```
这样可以减少代码量,使代码更加简洁。
This clip is not recordable
As an AI language model, I cannot record or access any audio or video clips. However, if you are trying to record a clip and encountering an error message stating that it is not recordable, it could be due to various reasons such as copyright protection, device compatibility issues or restricted access permissions. Please provide more context or seek technical assistance for further help.
阅读全文