Skip to content

Commit ecfe1cb

Browse files
authored
Merge pull request #41 from educorvi/develop
fix type guard for ArrayLike
2 parents 6a913f0 + 003942a commit ecfe1cb

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@educorvi/rita",
5+
"comment": "fix type guard for ArrayLike",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@educorvi/rita"
10+
}

rita-core/src/Assertions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export function assertDuration(
5454
}
5555
}
5656

57-
export function hasLength(
57+
export function assertArrayLike(
5858
value: unknown,
5959
context: Formula
6060
): asserts value is unknown & { length: number } {
61-
if (!value || !value.hasOwnProperty('length')) {
61+
if (!value?.hasOwnProperty('length')) {
6262
throw new HasNoLengthError(context, value);
6363
}
6464
}

rita-core/src/logicElements/Macro.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Formula, FormulaResults } from './Formula';
22
import { Atom } from './Atom';
3-
import { hasLength } from '../Assertions';
3+
import { assertArrayLike } from '../Assertions';
44

55
export class Macro extends Formula {
66
/** Indicates the type of this atom **/
@@ -21,7 +21,7 @@ export class Macro extends Formula {
2121
return new Date();
2222
case 'length':
2323
const ar = await this.array?.evaluate(data);
24-
hasLength(ar, this);
24+
assertArrayLike(ar, this);
2525
return ar.length;
2626
}
2727
}

0 commit comments

Comments
 (0)