Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve type definitions, mark tslib as dep (#5)
- Loading branch information
Showing
7 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"synckit": patch | ||
--- | ||
|
||
fix: improve type definitions, mark tslib as dep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type AnyFn<T = any, R extends any[] = any[]> = (...args: R) => T | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-type-alias | ||
export type AnyPromise = Promise<any> | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-type-alias | ||
export type AnyAsyncFn = AnyFn<AnyPromise> | ||
|
||
export type Syncify<T extends AnyFn<AnyPromise>> = T extends ( | ||
...args: infer Args | ||
) => Promise<infer R> | ||
? (...args: Args) => R | ||
: never | ||
|
||
export type PromiseType<T extends AnyPromise> = T extends Promise<infer R> | ||
? R | ||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import { TypeEqual, expectType } from 'ts-expect' | ||
|
||
import { | ||
AnyPromise, | ||
createSyncFn, | ||
PromiseType, | ||
runAsWorker, | ||
Syncify, | ||
} from 'synckit' | ||
|
||
// @ts-expect-error | ||
expectType<Syncify<() => 1>>(true) | ||
|
||
expectType<TypeEqual<Syncify<() => Promise<true>>, () => true>>(true) | ||
expectType<TypeEqual<Syncify<() => AnyPromise>, () => PromiseType<AnyPromise>>>( | ||
true, | ||
) | ||
expectType<TypeEqual<Syncify<() => Promise<never>>, () => never>>(true) | ||
|
||
// @ts-expect-error | ||
createSyncFn<() => 0>('') | ||
|
||
// @ts-expect-error | ||
expectType<() => true>(createSyncFn<() => Promise<1>>('')) | ||
|
||
expectType<() => true>(createSyncFn<() => Promise<true>>('')) | ||
expectType<() => true>(createSyncFn<() => Promise<never>>('')) | ||
|
||
// @ts-expect-error | ||
runAsWorker(() => 1) | ||
|
||
runAsWorker<() => Promise<number>>(() => Promise.resolve(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters