Skip to content

Commit d72ce11

Browse files
committed
fix: allow for .plugin().plugin() chaining
1 parent 0a594f8 commit d72ce11

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ type ReturnTypeOf<T extends AnyFunction | AnyFunction[]> = T extends AnyFunction
2929

3030
export class Base {
3131
static plugins: TestPlugin[] = [];
32-
static plugin<T extends TestPlugin | TestPlugin[]>(plugin: T) {
32+
static plugin<
33+
S extends Constructor<any> & { plugins: any[] },
34+
T extends TestPlugin | TestPlugin[]
35+
>(this: S, plugin: T) {
3336
const currentPlugins = this.plugins;
3437

3538
const BaseWithPlugins = class extends this {
@@ -40,12 +43,14 @@ export class Base {
4043
return BaseWithPlugins as typeof BaseWithPlugins & Constructor<Extension>;
4144
}
4245

43-
static defaults(defaults: Options) {
44-
return class OctokitWithDefaults extends this {
45-
constructor(options: Options = {}) {
46-
super(Object.assign({}, defaults, options));
46+
static defaults<S extends Constructor<any>>(this: S, defaults: Options) {
47+
const OctokitWithDefaults = class extends this {
48+
constructor(...args: any[]) {
49+
super(Object.assign({}, defaults, args[0] || {}));
4750
}
4851
};
52+
53+
return OctokitWithDefaults;
4954
}
5055

5156
constructor(options: Options = {}) {

0 commit comments

Comments
 (0)