TypeErrors when iterating over results from GetDialogs
See original GitHub issueHello - 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:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
you could use instanceof and that will fix it all.
Typescript isn’t that smart to know what type you want by eliminating attributes.
Closing for now