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

Allow non promise in input #6

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "combine-promises",
"author": "slorber",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
type UnwrapPromise<P extends Promise<unknown>> = P extends PromiseLike<infer V>
? V
: never;
type UnwrapPromise<P extends unknown> = P extends PromiseLike<infer V> ? V : P;

type Input = Record<string | number | symbol, Promise<unknown>>;
type Input = Record<string | number | symbol, unknown>;

type Result<Obj extends Input> = {
[P in keyof Obj]: UnwrapPromise<Obj[P]>;
Expand Down
4 changes: 1 addition & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ describe('combinePromises', () => {
expect(result).toEqual({ user: createUser(1), company: createCompany(2) });
});

it('can handle sync values, but TS errors', async () => {
// @ts-expect-error: "company" value should be async/Promise
it('can handle sync values', async () => {
const result: { user: User; company: Company } = await combinePromises({
user: fetchUser(1),
// @ts-expect-error: "company" value should be async/Promise
company: createCompany(2),
});
expect(result).toEqual({ user: createUser(1), company: createCompany(2) });
Expand Down
Loading