Skip to content

Commit 1b1e8b1

Browse files
authored
fix(types, clerk-js): Update Errors interface to allow null for raw and global error arrays (#6677)
1 parent 9796fbf commit 1b1e8b1

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

.changeset/smart-seas-breathe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@clerk/clerk-js": patch
3+
"@clerk/types": patch
4+
---
5+
6+
Update the experimental `Errors` interface to allow null for raw and global error arrays

packages/clerk-js/src/core/signals.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,38 @@ function errorsToParsedErrors(error: unknown): Errors {
5252
captcha: null,
5353
legalAccepted: null,
5454
},
55-
raw: [],
56-
global: [],
55+
raw: null,
56+
global: null,
5757
};
5858

5959
if (!error) {
6060
return parsedErrors;
6161
}
6262

6363
if (!isClerkAPIResponseError(error)) {
64-
parsedErrors.raw.push(error);
65-
parsedErrors.global.push(error);
64+
parsedErrors.raw = [error];
65+
parsedErrors.global = [error];
6666
return parsedErrors;
6767
}
6868

69-
parsedErrors.raw.push(...error.errors);
70-
7169
error.errors.forEach(error => {
70+
if (parsedErrors.raw) {
71+
parsedErrors.raw.push(error);
72+
} else {
73+
parsedErrors.raw = [error];
74+
}
75+
7276
if ('meta' in error && error.meta && 'paramName' in error.meta) {
7377
const name = snakeToCamel(error.meta.paramName);
7478
parsedErrors.fields[name as keyof typeof parsedErrors.fields] = error;
7579
return;
7680
}
7781

78-
parsedErrors.global.push(error);
82+
if (parsedErrors.global) {
83+
parsedErrors.global.push(error);
84+
} else {
85+
parsedErrors.global = [error];
86+
}
7987
});
8088

8189
return parsedErrors;

packages/react/src/stateProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const defaultErrors = (): Errors => ({
1717
captcha: null,
1818
legalAccepted: null,
1919
},
20-
raw: [],
21-
global: [],
20+
raw: null,
21+
global: null,
2222
});
2323

2424
export class StateProxy implements State {

packages/types/src/state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export interface Errors {
7676
/**
7777
* The raw, unparsed errors from the Clerk API.
7878
*/
79-
raw: unknown[];
79+
raw: unknown[] | null;
8080
/**
8181
* Parsed errors that are not related to any specific field.
8282
*/
83-
global: unknown[]; // does not include any errors that could be parsed as a field error
83+
global: unknown[] | null; // does not include any errors that could be parsed as a field error
8484
}
8585

8686
/**

0 commit comments

Comments
 (0)