Skip to content

Commit

Permalink
chore: fix an array of types
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Aug 1, 2024
1 parent d2d939d commit bdff20c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions packages/core/__tests__/singleton/Auth/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ describe('type validity', () => {
describe('JWT type', () => {
it('can contain property that has a value as array of JsonObject', () => {
const value: JWT = {
payload: { otherProperty: 'value' },
payload: { otherProperty: [{ key: '123' }] },
toString: () => 'mock',
};
const a = value.payload.otherProperty as { key: string }[];

expect(a).toEqual('value');
expect(a).toEqual([{ key: '123' }]);
});

it('can contain property that has a value as array of JsonObject and JsonPrimitive', () => {
const value: JWT = {
payload: { otherProperty: [1, 2, 'hi', { key: 'value' }] },
toString: () => 'mock',
};
const a = value.payload.otherProperty as (
| { key: string }
| number
| string
)[];

expect(a).toEqual([1, 2, 'hi', { key: 'value' }]);
});
});
});
2 changes: 1 addition & 1 deletion packages/core/src/singleton/Auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface JwtPayloadStandardFields {
type JsonPrimitive = null | string | number | boolean;

/** JSON array type */
type JsonArray = JsonPrimitive[] | JsonObject[];
type JsonArray = (JsonPrimitive | JsonObject)[];

/** JSON Object type */
interface JsonObject {
Expand Down

0 comments on commit bdff20c

Please sign in to comment.