Skip to content

Commit

Permalink
Use unknown for inferrence.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Mar 19, 2019
1 parent a9aa5bf commit e15bb5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export interface TaskMetadata {
stopTime: number;
}

export default class Task<Ctx extends Context, Events extends TaskEvents> extends Emitter<Events> {
export default class Task<
Ctx extends Context,
Events extends TaskEvents = TaskEvents
> extends Emitter<Events> {
action: TaskAction<Ctx>;

// @ts-ignore Set after instantiation
Expand Down
12 changes: 7 additions & 5 deletions packages/emitter/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// prettier-ignore
export type Arguments<T> =
T extends (...args: infer A) => any ? A :
T extends any[] ? T :
T extends (...args: infer A) => unknown ? A :
T extends unknown[] ? T :
never;

// VALID
// type A = Arguments<[number]>;
// type B = Arguments<[number, string]>;
// type C = Arguments<[number, boolean, string?]>;
Expand All @@ -12,14 +13,15 @@ export type Arguments<T> =
// type F = Arguments<(a: string, b: number) => boolean | void>;
// type G = Arguments<(a: string, b: number, c?: object) => string>;

export type WaterfallArgument<T> = T extends (value: infer A) => any ? A : T;
export type WaterfallArgument<T> = T extends (value: infer A) => unknown ? A : T;

// prettier-ignore
export type ListenerType<T> =
T extends (...args: any[]) => boolean | any ? T :
T extends any[] ? (...args: T) => boolean | void :
T extends (...args: any[]) => any ? T :
T extends unknown[] ? (...args: T) => boolean | void :
never;

// VALID
// type H = ListenerType<(a: string, b: number, c?: object) => string>;
// type I = ListenerType<(a: string) => Promise<boolean>>;
// type J = ListenerType<(a: string, b: number) => boolean | void>;
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8798,9 +8798,9 @@ typedarray@^0.0.6:
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.3.3, typescript@~3.3.1:
version "3.3.3"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.3.3.tgz#f1657fc7daa27e1a8930758ace9ae8da31403221"
integrity sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A==
version "3.3.3333"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6"
integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw==

uglify-js@^3.1.4:
version "3.4.9"
Expand Down

0 comments on commit e15bb5b

Please sign in to comment.