question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeErrors when iterating over results from GetDialogs

See original GitHub issue

Hello - I have some different type errors that are a bit confusing. I am calling client.getDialogs({})

AppDir/src/lib/telegram.ts (133,26): Property 'id' does not exist on type 'never'.
AppDir/src/lib/telegram.ts (134,26): Property 'title' does not exist on type 'never'.
AppDir/src/lib/telegram.ts (135,26): Property 'accessHash' does not exist on type 'never'.
src/lib/telegram.ts:131:19 - error TS2339: Property 'className' does not exist on type 'Dialog'.

131         && dialog.className === 'Channel'
                      ~~~~~~~~~

src/lib/telegram.ts:133:26 - error TS2339: Property 'title' does not exist on type 'Entity'.
  Property 'title' does not exist on type 'User'.

133         && dialog.entity.title != null
                             ~~~~~

src/lib/telegram.ts:134:26 - error TS2339: Property 'accessHash' does not exist on type 'Entity'.
  Property 'accessHash' does not exist on type 'Chat'.

134         && dialog.entity.accessHash != null) {

The code I’m calling is:

const dialogs = await client.getDialogs({});
const entities = dialogs.reduce((result, dialog) => {
  if (dialog.entity != null
      && dialog.className === 'Channel'
      && dialog.entity.id != null
      && dialog.entity.title != null
      && dialog.entity.accessHash != null) {
    const { id, title, accessHash } = dialog.entity
    result.push({ id, title, accessHash });
  }
  return result;
}, []);

My code works and I get the expected variables set (id, title, accessHash). What can I do to satisfy the errors above?.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
painorcommented, Sep 10, 2021

you could use instanceof and that will fix it all.

   if (dialog.entity instanceof Api.Channel) {
        const { id, title, accessHash } = dialog.entity

Typescript isn’t that smart to know what type you want by eliminating attributes.

0reactions
KidA001commented, Sep 15, 2021

Closing for now

Read more comments on GitHub >

github_iconTop Results From Across the Web

python: Type Error while iterating over list consisting of tuples ...
since your trying to iterate through the length of planets (which is an int) you're not getting the results that you're expecting.
Read more >
Iterating over Results - Rust By Example
Result implements FromIterator so that a vector of results ( Vec<Result<T, E>> ) can be turned into a result with a vector (...
Read more >
TypeError: 'x' is not iterable - JavaScript - MDN Web Docs
In JavaScript, Object s are not iterable unless they implement the iterable protocol. Therefore, you cannot use for...of to iterate over the properties...
Read more >
TelegramClient — Telethon 1.26.1 documentation
Returns: The result of the request (often a TLObject ) or a list of results if more than one ... Property with the...
Read more >
Telethon Documentation - Read the Docs
Iterates over a file download, yielding chunks of the file. Dialogs ... Answers the inline query with the given results. ... Get dialogs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found