Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript check ERROR in node_modules/getstream/src/utils.ts:103:15 #536

Closed
nima-lighthouse opened this issue Jan 30, 2023 · 0 comments · Fixed by #537
Closed

Typescript check ERROR in node_modules/getstream/src/utils.ts:103:15 #536

nima-lighthouse opened this issue Jan 30, 2023 · 0 comments · Fixed by #537

Comments

@nima-lighthouse
Copy link
Contributor

nima-lighthouse commented Jan 30, 2023

Typecheck doesn't pass on the library init. Cannot start running the app

ERROR in node_modules/getstream/src/utils.ts:103:15
TS2769: No overload matches this call.
  Overload 1 of 2, '(o: {}): string[]', gave the following error.
    Argument of type 'T' is not assignable to parameter of type '{}'.
  Overload 2 of 2, '(o: object): string[]', gave the following error.
    Argument of type 'T' is not assignable to parameter of type 'object'.
    101 |   const cloned = {};
    102 |
  > 103 |   Object.keys(obj).forEach((k) => {
        |               ^^^
    104 |     // @ts-expect-error
    105 |     cloned[k] = replaceStreamObjects(obj[k]);
    106 |   });
**To Reproduce**

Versions
"getstream": "^8.1.0",
"react": "^18.0.0",
"typescript": "^4.9.4",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.40.0",

Simple fix solution in the SDK:
In getstream/src/utils.ts

// TODO: refactor and add proper types
function replaceStreamObjects<T, V>(obj: T): V {
  // @ts-expect-error
  if (Array.isArray(obj)) return obj.map((v) => replaceStreamObjects(v));

  // @ts-expect-error
  if (Object.prototype.toString.call(obj) !== '[object Object]') return obj;

  // @ts-expect-error
  if (typeof obj.ref === 'function') return obj.ref();

  const cloned = {};
  
  // @ts-expect-error <--------- ADDITIONAL COMMENT TO FIX THE ERROR
  Object.keys(obj).forEach((k) => {
    // @ts-expect-error
    cloned[k] = replaceStreamObjects(obj[k]);
  });

  // @ts-expect-error
  return cloned;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant