Skip to content

Commit 964c604

Browse files
committed
feat: inher constructor options via Base.defaults()
1 parent bd9d789 commit 964c604

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

index.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
export namespace Base {
1+
export declare namespace Base {
22
interface Options {
3+
version: string;
34
[key: string]: unknown;
45
}
56
}
@@ -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
@@ -6,13 +6,16 @@ import { barPlugin } from "./plugins/bar/index.js";
66
import { voidPlugin } from "./plugins/void/index.js";
77
import { withOptionsPlugin } from "./plugins/with-options";
88

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

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

1416
const FooBase = Base.plugin(fooPlugin).defaults({
1517
default: "value",
18+
version: "1.2.3",
1619
});
1720
const fooBase = new FooBase({
1821
option: "value",
@@ -23,13 +26,17 @@ expectType<string>(fooBase.options.option);
2326
expectType<string>(fooBase.foo);
2427

2528
const BaseWithVoidPlugin = Base.plugin(voidPlugin);
26-
const baseWithVoidPlugin = new BaseWithVoidPlugin();
29+
const baseWithVoidPlugin = new BaseWithVoidPlugin({
30+
version: "1.2.3",
31+
});
2732

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

3136
const BaseWithFooAndBarPlugins = Base.plugin(barPlugin, fooPlugin);
32-
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins();
37+
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins({
38+
version: "1.2.3",
39+
});
3340

3441
expectType<string>(baseWithFooAndBarPlugins.foo);
3542
expectType<string>(baseWithFooAndBarPlugins.bar);
@@ -42,7 +49,9 @@ const BaseWithVoidAndNonVoidPlugins = Base.plugin(
4249
voidPlugin,
4350
fooPlugin
4451
);
45-
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins();
52+
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins({
53+
version: "1.2.3",
54+
});
4655

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

0 commit comments

Comments
 (0)