Skip to content

Commit

Permalink
Some play with types
Browse files Browse the repository at this point in the history
  • Loading branch information
RuneKR committed Sep 30, 2021
1 parent f28a453 commit 00cec4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/core/appShell/Worker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// comlink inspired

type PromisifyProp<T> = T extends Promise<unknown> ? T : Promise<T>;
type PromisifyFunc<T> = T extends (...args: infer TArguments) => infer TReturn ? (...args: TArguments) => PromisifyProp<TReturn> : unknown

type Promisify<T> = T extends Function ? PromisifyFunc<T> : Promise<T>;

type ProxiedObject<T> = { [P in keyof T]: Promisify<T[P]> };

interface Demo {
hello: string;
demo(hello: string): boolean;
hope(hello: string): Promise<string>;
}

type Test = ProxiedObject<Demo>;
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API/Using_channel_messaging

0 comments on commit 00cec4b

Please sign in to comment.