Skip to content

Commit

Permalink
chore: minor type cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeiscontent committed Apr 30, 2024
1 parent be32a14 commit 5e00132
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/conform-dom/formdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function normalize<
* Flatten a tree into a dictionary
*/
export function flatten(
data: Record<string | number | symbol, unknown> | Array<unknown> | undefined,
data: unknown,
options?: {
resolve?: (data: unknown) => unknown | null;
prefix?: string;
Expand Down Expand Up @@ -307,7 +307,7 @@ export function flatten(

if (Array.isArray(data)) {
processArray(data, prefix);
} else {
} else if (data && isPlainObject(data)) {
processObject(data, prefix);
}
}
Expand Down
11 changes: 2 additions & 9 deletions packages/conform-dom/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ export function setState(

Object.assign(
state,
// @ts-expect-error FIXME flatten should be more flexible
flatten(result, {
resolve(data) {
if (isPlainObject(data) || Array.isArray(data)) {
Expand Down Expand Up @@ -524,14 +523,11 @@ export function setListState(
});
}

export function serialize<Schema>(
defaultValue: DefaultValue<Schema>,
): FormValue<Schema> {
export function serialize<Schema>(defaultValue: Schema): FormValue<Schema> {
if (isPlainObject(defaultValue)) {
// @ts-expect-error FIXME
return Object.entries(defaultValue).reduce<Record<string, unknown>>(
(result, [key, value]) => {
// @ts-ignore-error FIXME
result[key] = serialize(value);
return result;
},
Expand All @@ -540,10 +536,7 @@ export function serialize<Schema>(
} else if (Array.isArray(defaultValue)) {
// @ts-expect-error FIXME
return defaultValue.map(serialize);
} else if (
// @ts-ignore-error FIXME
defaultValue instanceof Date
) {
} else if (defaultValue instanceof Date) {
// @ts-expect-error FIXME
return defaultValue.toISOString();
} else if (typeof defaultValue === 'boolean') {
Expand Down

0 comments on commit 5e00132

Please sign in to comment.