Skip to content

Commit bf15c10

Browse files
committed
feat: inher constructor options via Base.defaults()
1 parent 4c8cec9 commit bf15c10

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

index.d.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export declare namespace Base {
2-
type Options = {
2+
interface Options {
3+
version: string;
34
[key: string]: unknown;
4-
};
5+
}
56
}
67

78
declare type ApiExtension = {
@@ -56,7 +57,7 @@ export declare class Base<TOptions extends Base.Options = Base.Options> {
5657
options: TDefaults;
5758
};
5859
} & S;
59-
constructor(options?: TOptions);
60+
constructor(options: TOptions);
6061
options: TOptions;
6162
}
6263
export {};

index.test-d.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import { fooPlugin } from "./plugins/foo/index.js";
55
import { barPlugin } from "./plugins/bar/index.js";
66
import { voidPlugin } from "./plugins/void/index.js";
77

8-
const base = new Base();
8+
const base = new Base({
9+
version: "1.2.3",
10+
});
911

1012
// @ts-expect-error unknown properties cannot be used, see #31
1113
base.unknown;
1214

1315
const FooBase = Base.plugin(fooPlugin).defaults({
1416
default: "value",
17+
version: "1.2.3",
1518
});
1619
const fooBase = new FooBase({
1720
option: "value",
@@ -22,13 +25,17 @@ expectType<string>(fooBase.options.option);
2225
expectType<string>(fooBase.foo);
2326

2427
const BaseWithVoidPlugin = Base.plugin(voidPlugin);
25-
const baseWithVoidPlugin = new BaseWithVoidPlugin();
28+
const baseWithVoidPlugin = new BaseWithVoidPlugin({
29+
version: "1.2.3",
30+
});
2631

2732
// @ts-expect-error unknown properties cannot be used, see #31
2833
baseWithVoidPlugin.unknown;
2934

3035
const BaseWithFooAndBarPlugins = Base.plugin(barPlugin, fooPlugin);
31-
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins();
36+
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins({
37+
version: "1.2.3",
38+
});
3239

3340
expectType<string>(baseWithFooAndBarPlugins.foo);
3441
expectType<string>(baseWithFooAndBarPlugins.bar);
@@ -41,7 +48,9 @@ const BaseWithVoidAndNonVoidPlugins = Base.plugin(
4148
voidPlugin,
4249
fooPlugin
4350
);
44-
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins();
51+
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins({
52+
version: "1.2.3",
53+
});
4554

4655
expectType<string>(baseWithVoidAndNonVoidPlugins.foo);
4756
expectType<string>(baseWithVoidAndNonVoidPlugins.bar);

0 commit comments

Comments
 (0)