File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change
1
+ type Options = {
2
+ [ key : string ] : unknown ;
3
+ } ;
4
+
1
5
type ApiExtension = { [ key : string ] : any } ;
2
- type TestPlugin = ( instance : Base ) => ApiExtension | undefined ;
6
+ type TestPlugin = (
7
+ instance : Base ,
8
+ options : Options
9
+ ) => ApiExtension | undefined ;
3
10
type Constructor < T > = new ( ...args : any [ ] ) => T ;
4
11
5
12
/**
@@ -33,12 +40,24 @@ export class Base {
33
40
return BaseWithPlugins as typeof BaseWithPlugins & Constructor < Extension > ;
34
41
}
35
42
36
- constructor ( ) {
43
+ static defaults ( defaults : Options ) {
44
+ return class OctokitWithDefaults extends this {
45
+ constructor ( options : Options = { } ) {
46
+ super ( Object . assign ( { } , defaults , options ) ) ;
47
+ }
48
+ } ;
49
+ }
50
+
51
+ constructor ( options : Options = { } ) {
52
+ this . options = options ;
53
+
37
54
// apply plugins
38
55
// https://stackoverflow.com/a/16345172
39
56
const classConstructor = this . constructor as typeof Base ;
40
57
classConstructor . plugins . forEach ( plugin => {
41
- Object . assign ( this , plugin ( this ) ) ;
58
+ Object . assign ( this , plugin ( this , options ) ) ;
42
59
} ) ;
43
60
}
61
+
62
+ options : Options ;
44
63
}
You can’t perform that action at this time.
0 commit comments