Skip to content

Commit 68d4b6e

Browse files
AnastasiiaSvietlovagingerbenw
authored andcommitted
fix types
1 parent 0dd6dcf commit 68d4b6e

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

packages/core/src/lib/derecursify.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import isArray from './es-utils/is-array'
22

3-
const isSafeLiteral = (obj: unknown): boolean =>
3+
const isSafeLiteral = (obj: unknown): obj is string | number | boolean =>
44
typeof obj === 'string' || obj instanceof String ||
55
typeof obj === 'number' || obj instanceof Number ||
66
typeof obj === 'boolean' || obj instanceof Boolean
77

8-
const isError = (o: unknown) =>
8+
const isError = (o: unknown): o is Error =>
99
o instanceof Error || /^\[object (Error|(Dom)?Exception)]$/.test(Object.prototype.toString.call(o))
1010

1111
const throwsMessage = (err: Error) => '[Throws: ' + (err ? err.message : '?') + ']'
@@ -28,9 +28,9 @@ const safelyGetProp = (obj: Object, propName: keyof Object) => {
2828
* @returns a safe version of the given `data`
2929
*/
3030
const derecursify = (data: unknown): {} => {
31-
const seen: object[] | [][] = []
31+
const seen: Array<Object | []> = []
3232

33-
const visit = (obj: any): any => {
33+
const visit = (obj: unknown): any => {
3434
if (obj === null || obj === undefined) return obj
3535

3636
if (isSafeLiteral(obj)) {
@@ -51,11 +51,12 @@ const derecursify = (data: unknown): {} => {
5151
}
5252

5353
// handle arrays, and all iterable non-array types (such as Set)
54-
if (isArray(obj) || obj[Symbol.iterator]) {
54+
const symbol = Symbol.iterator as keyof object
55+
if (isArray(obj) || obj[symbol]) {
5556
seen.push(obj)
5657
const safeArray = []
5758
try {
58-
for (const value of obj) {
59+
for (const value of Object.keys(obj)) {
5960
safeArray.push(visit(value))
6061
}
6162
} catch (err: any) {

0 commit comments

Comments
 (0)