Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript error 1062: "Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method."

I'm getting this error with a Typescript application trying to use Snoowrap (Reddit API package), but I'm getting the above error (TS1062) and TypeScript is failing to compile.

The VoteableContent type has an expandReplies method which returns a promise, but when I try to await it I get the error.

Here's a truncated snippet of where I'm seeing it:

async getAllRepliers(content: Submission | Comment): Promise<string[]> {            
    await content.expandReplies()
}

Submission and Comment both extend VoteableContent and have the method, but TypeScript is throwing the error there.

This seems to be an issue with Typescript or the typings rather then my code or snoowrap's code? I'm unsure. I'm using the latest versions all around (TS 3.3.3, snoowrap 1.15.2, @types/snoowrap 1.15.3) so not sure what I can do or how I would fix this. Thanks.

like image 862
cogm Avatar asked Feb 17 '19 17:02

cogm


1 Answers

It seems the method already implements and resolves its own then() method, meaning it sort of awaits itself.

I read this post to come to that conclusion: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method

EDIT: I've tested this with snoowrap.Submission's upvote() function which had the same problem, and it works synchronously without an await.

like image 71
David Shortman Avatar answered Nov 12 '22 07:11

David Shortman