-
-
Notifications
You must be signed in to change notification settings - Fork 545
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
Add Unpromise
type
#42
Conversation
What’s the real-world use-case for this? |
@sindresorhus if you want to get the return type of an async function for example. type AsyncRequest = (...args: any) => Promise<'foobar'>;
type FooBar = Unpromise<ReturnType<AsyncRequest>>; // 'foobar' |
@streamich See discussion in #38 |
479173a
to
1c76afe
Compare
@streamich Are you still interested in finishing this? |
@@ -0,0 +1,10 @@ | |||
/** | |||
Unwraps `Promise` and returns lifted type. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write about some real-world use-cases where it can be useful. (It can be hard sometimes for users to see where they would use something) - https://github.com/sindresorhus/type-fest/blob/master/.github/contributing.md#submitting-a-new-type
@example | ||
``` | ||
type A = Promise<string>; | ||
type InnerType = Unpromise<A>; // string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example here could be more realistic:
Example code block with a realistic example. - https://github.com/sindresorhus/type-fest/blob/master/.github/contributing.md#submitting-a-new-type
|
@@ -0,0 +1,10 @@ | |||
/** | |||
Unwraps `Promise` and returns lifted type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description could be clearer and more verbose on what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* Returns the type that is wrapped inside a `Promise` type.
*
* @example
* import { asyncFunction } from 'api';
* import { UnwrapPromise } from 'type-fest';
*
* let data: UnwrapPromise<ReturnType<typeof asyncFunction>>;
*
* async function setValue () {
* data = await asyncFunction();
* }
*
* setValue();
*/
How's this, bud?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
UnwrapPromise => Unpromise
@@ -71,6 +71,7 @@ Click the type names for complete docs. | |||
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given properties. | |||
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of a `object`/`Map`/`Set`/`Array` type. | |||
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). | |||
- [`Unpromise`](source/unpromise.d.ts) - Returns type wrapped in `Promise`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [`Unpromise`](source/unpromise.d.ts) - Returns type wrapped in `Promise`. | |
- [`Unpromise`](source/unpromise.d.ts) - Returns the type that is wrapped inside a `Promise` type. |
import {expectType, expectError} from 'tsd'; | ||
import {Unpromise} from '..'; | ||
|
||
type Str = Unpromise<Promise<string>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use acronyms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh god, I love you for saying that. 😛
I'd be interested in taking over this, if you're happy with that, @sindresorhus. |
@resynth1943 Sure, go ahead 👍 |
Gotcha. I'll whip up a PR. ❤️ |
There are a few possible names we could use for this too.
Or should we stick with |
I like |
Let's do it. ❤️ |
Adds
Unpromise
type.