refactor(editor): enable the noUncheckedIndexedAccess rule for the block-database package (#9691)

close: BS-2269
This commit is contained in:
zzj3720
2025-01-14 14:35:46 +00:00
parent aa2a8fbf9b
commit ff295f383f
24 changed files with 324 additions and 344 deletions
@@ -31,7 +31,7 @@ type Create<
};
export type PropertyModel<
Type extends string = string,
PropertyData extends Record<string, unknown> = Record<string, never>,
PropertyData extends Record<string, unknown> = Record<string, unknown>,
CellData = unknown,
> = {
type: Type;
@@ -38,12 +38,7 @@ export type PropertyConfig<
value?: Value;
}>
) => unknown[];
cellToString: (
config: WithCommonPropertyConfig<{
value: Value;
data: Data;
}>
) => string;
cellToString: (config: { value: Value; data: Data }) => string;
cellFromString: (
config: WithCommonPropertyConfig<{
value: string;
@@ -286,7 +286,6 @@ export abstract class SingleViewBase<
this.dataSource.propertyMetaGet(type).config.cellToString({
value: this.dataSource.cellValueGet(rowId, propertyId),
data: this.propertyDataGet(propertyId),
dataSource: this.dataSource,
}) ?? ''
);
}
@@ -1,3 +1,6 @@
import { format } from 'date-fns/format';
import { parse } from 'date-fns/parse';
import { t } from '../../core/logical/type-presets.js';
import { propertyType } from '../../core/property/property-config.js';
@@ -6,12 +9,12 @@ export const datePropertyModelConfig = datePropertyType.modelConfig<number>({
name: 'Date',
type: () => t.date.instance(),
defaultData: () => ({}),
cellToString: ({ value }) => value?.toString() ?? '',
cellToString: ({ value }) => format(value, 'yyyy-MM-dd'),
cellFromString: ({ value }) => {
const isDateFormat = !isNaN(Date.parse(value));
const date = parse(value, 'yyyy-MM-dd', new Date());
return {
value: isDateFormat ? +new Date(value) : null,
value: +date,
};
},
cellToJson: ({ value }) => value ?? null,