Promise typings doesn't respect subclasses

Open
#45,427 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
compilers

Research direction

Start with the linked TypeScript playground example and compare the Promise subclass behavior described in the issue with the ECMAScript Promise constructor documentation. The work is done when well-known Promise methods are typed to preserve the subclass instance, subject to resolving the issue's HKT concern.

Written by the indexing model from the issue text.

Description

Awaiting More Feedback Suggestion

For promise subclasses all well-known Promise methods return instance of subclass. Code below is legal and promise subclasses behaviour cleanly documented https://tc39.es/ecma262/#sec-promise-constructor

However I'm not sure that this is easy fixable without HKT

Sample Code

image

https://www.typescriptlang.org/play?ts=4.4.0-beta#code/MYGwhgzhAECyCeAFATgewLYEsIFMA8AKgHzQ4AeALjgHYAmMKG2+x0A3gFDTfQAOArgCMQmYNGDIcYKrQCCFaAF5o1HAHdoAEWk4AFAEoA3BwC+HDsFTUICsgC44SNFlx4AjCWUJGLnADpJCFQQADc9NyMLKxtoeAdvZ2Y8ACZPaDI-CgALGl0DJRI2bLQNZJNIqOtg-xBUAHNdDIkpGXkAGli-Zp05CiMgA

Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/TypeScript

All issues in microsoft/TypeScript

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.