Skip to content

Commit bedb7f4

Browse files
authored
fix: avoid base to be set to an intersection with void if a plugin returns void (#53)
1 parent 2e48e16 commit bedb7f4

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare type ReturnTypeOf<T extends AnyFunction | AnyFunction[]> =
2121
T extends AnyFunction
2222
? ReturnType<T>
2323
: T extends AnyFunction[]
24-
? UnionToIntersection<ReturnType<T[number]>>
24+
? UnionToIntersection<Exclude<ReturnType<T[number]>, void>>
2525
: never;
2626

2727
export declare class Base<TOptions extends Options = Options> {

index.test-d.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,56 @@ import { Base } from "./index.js";
33

44
const fooPlugin = () => {
55
return {
6-
foo: () => "foo",
6+
foo: "foo",
77
};
88
};
9+
const barPlugin = () => {
10+
return {
11+
bar: "bar",
12+
};
13+
};
14+
15+
const voidPlugin = () => {
16+
// returns void
17+
};
18+
19+
const base = new Base();
20+
21+
// @ts-expect-error unknown properties cannot be used, see #31
22+
base.unknown;
923

10-
const MyBase = Base.plugin(fooPlugin).defaults({
24+
const FooBase = Base.plugin(fooPlugin).defaults({
1125
default: "value",
1226
});
13-
const base = new MyBase({
27+
const fooBase = new FooBase({
1428
option: "value",
1529
});
1630

17-
expectType<string>(base.options.default);
18-
expectType<string>(base.options.option);
19-
expectType<string>(base.foo());
31+
expectType<string>(fooBase.options.default);
32+
expectType<string>(fooBase.options.option);
33+
expectType<string>(fooBase.foo);
34+
35+
const BaseWithVoidPlugin = Base.plugin(voidPlugin);
36+
const baseWithVoidPlugin = new BaseWithVoidPlugin();
2037

2138
// @ts-expect-error unknown properties cannot be used, see #31
22-
base.unknown;
39+
baseWithVoidPlugin.unknown;
40+
41+
const BaseWithFooAndBarPlugins = Base.plugin(barPlugin, fooPlugin);
42+
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins();
43+
44+
expectType<string>(baseWithFooAndBarPlugins.foo);
45+
expectType<string>(baseWithFooAndBarPlugins.bar);
46+
47+
// @ts-expect-error unknown properties cannot be used, see #31
48+
baseWithFooAndBarPlugins.unknown;
49+
50+
const BaseWithVoidAndNonVoidPlugins = Base.plugin(
51+
barPlugin,
52+
voidPlugin,
53+
fooPlugin
54+
);
55+
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins();
56+
57+
expectType<string>(baseWithVoidAndNonVoidPlugins.foo);
58+
expectType<string>(baseWithVoidAndNonVoidPlugins.bar);

0 commit comments

Comments
 (0)