Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PromiseLike<T> intead of Promise<T>. Fixes #39 #40

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

rkatic
Copy link
Contributor

@rkatic rkatic commented Apr 27, 2020

No description provided.

@rollingversions
Copy link

rollingversions bot commented Apr 27, 2020

Change Log for is-promise (3.0.0 → 4.0.0)

Breaking Changes

  • Use PromiseLike instead of Promise in TypeScript

    This is only a breaking change for TypeScript users.

    In the following code:

    function foo(x: PromiseLike<string> | string) {
      if (isPromise(x)) {
        return x;
      } else {
        return Promise.resolve(x);
      }
    }

    TypeScript would previously have incorrectly inferred foo as returning Promise<string> when in fact it returns PromiseLike<string>. The latest version fixes this. If you instead had the following code, it should work exactly the same as before:

    function foo(x: Promise<string> | string) {
      if (isPromise(x)) {
        return x;
      } else {
        return Promise.resolve(x);
      }
    }

    This update is to reflect the fact that is-promise does "duck" typing, rather than an instanceof check.

Edit changelog

@rkatic
Copy link
Contributor Author

rkatic commented Apr 27, 2020

Be aware that this is likely a braking change for TS users.
If, after testing a thenable, the object is used as a real promise (for example using other methods than then) without Promise.resolve it first, TS will start to fail with error(s).

@ForbesLindesay ForbesLindesay merged commit 5a240f6 into then:master Apr 27, 2020
@ForbesLindesay
Copy link
Member

Thanks, this will shortly be released as 4.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants