8000 Typing custom promises. Advice please. · Issue #20251 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Typing custom promises. Advice please. #20251
Closed
@electricessence

Description

@electricessence

So the types surrounding promises has changed quite a bit over time and I've struggled to properly maintain my own promise lib and have it work happily with async/await and typing.

Since Promise<T> is an actual type in the lib, it apparently can't be used as an alias to represent a promise that is not the built in ES6 promise no?

I recently ran into:

TS2420: Class 'PromiseBase<T>' incorrectly implements interface 'Promise<T>'.
Property '[Symbol.toStringTag]' is missing in type 'PromiseBase<T>'

Where PromiseBase<T> is my base class for a variety of different promise types.
I can resolve this issue by simply adding the following to PromiseBase<T>:

readonly [Symbol.toStringTag]: "Promise"; // Must be "Promise" and cannot be "PromiseBase".

Which I don't mind, but I feel it's not correct.

Any thoughts on the right thing to do here? I think I have a solid promise lib, and want to keep using it. But I have to name it something other than Promise for the compiler to be happy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0