Skip to content

Commit 2e4ac32

Browse files
committed
feat(structures): apply typeguards
1 parent cd87021 commit 2e4ac32

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/structures/src/presences/activities/ActivityParty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ActivityParty<Omitted extends keyof GatewayActivityParty | '' = ''>
3838
* The current size of the party
3939
*/
4040
public get currentSize() {
41-
const array = this[kData].size as number[];
41+
const array = this[kData].size;
4242

4343
return array ? (isArrayFieldSet(array, 0, 'number') ? array[0] : null) : null;
4444
}
@@ -47,7 +47,7 @@ export class ActivityParty<Omitted extends keyof GatewayActivityParty | '' = ''>
4747
* The maximum size of the party
4848
*/
4949
public get maximumSize() {
50-
const array = this[kData].size as number[];
50+
const array = this[kData].size;
5151

5252
return array ? (isArrayFieldSet(array, 1, 'number') ? array[1] : null) : null;
5353
}

packages/structures/src/utils/type-guards.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export function isFieldSet<Value extends object, Key extends string, Type extend
4040
* @param targetIndex - The target index of the element whose type to narrow
4141
* @param type - The type to compare against
4242
*/
43-
export function isArrayFieldSet(array: unknown[], targetIndex: number, type: TypeofType): boolean {
43+
export function isArrayFieldSet<Type extends TypeofType, Index extends number>(
44+
array: unknown,
45+
targetIndex: Index,
46+
type: Type,
47+
): array is Record<Index, Type> & unknown[] {
4448
return Array.isArray(array)
4549
? array.length >= targetIndex
4650
? // eslint-disable-next-line valid-typeof

0 commit comments

Comments
 (0)