( value: unknown )
| 11 | ): Array<unknown> | { [key: string]: unknown }; |
| 12 | export function toJS(value: unknown): unknown; |
| 13 | export function toJS( |
| 14 | value: unknown |
| 15 | ): Array<unknown> | { [key: string]: unknown } | unknown { |
| 16 | if (!value || typeof value !== 'object') { |
| 17 | return value; |
| 18 | } |
| 19 | if (!isCollection(value)) { |
| 20 | if (!isDataStructure(value)) { |
| 21 | return value; |
| 22 | } |
| 23 | // @ts-expect-error until Seq has been migrated to TypeScript |
| 24 | value = Seq(value); |
| 25 | } |
| 26 | if (isKeyed(value)) { |
| 27 | const result: { [key: string]: unknown } = {}; |
| 28 | // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type |
| 29 | value.__iterate((v, k) => { |
| 30 | if (isProtoKey(k)) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | result[k] = toJS(v); |
| 35 | }); |
| 36 | return result; |
| 37 | } |
| 38 | const result: Array<unknown> = []; |
| 39 | // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types |
| 40 | value.__iterate((v: unknown) => { |
| 41 | result.push(toJS(v)); |
| 42 | }); |
| 43 | return result; |
| 44 | } |
no test coverage detected