Skip to content

Commit fc8b3a2

Browse files
committed
feat(plugins-manager): further improve types
1 parent ee20047 commit fc8b3a2

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/plugins-manager/src/addPlugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @typedef {import('../types/main').MetaPlugin} MetaPlugin */
22

3-
/** @type {import('../types/main').AddPluginType} */
3+
/**
4+
* @template {Function} T
5+
* @param {import('../types/main').AddPluginOptions<T>} metaPluginAndOptions
6+
*/
47
export function addPlugin(metaPluginAndOptions) {
58
const {
69
name,

packages/plugins-manager/types/main.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ type AnyFn = (...args: any[]) => any;
33
export interface MetaPlugin<F = AnyFn> {
44
name: string;
55
plugin: F extends (options?: infer O) => P ? F : any;
6-
options?: F extends (options: infer O) => P ? O : any;
6+
options?: /* prettier-ignore */ (
7+
F extends (eleventyConfig: any, options?: infer O) => void ? O
8+
: F extends (options: infer O) => P ? O
9+
: any
10+
);
711
}
812

913
export interface MetaPluginWrapable extends MetaPlugin {
1014
__noWrap?: boolean;
1115
}
1216

13-
interface AddPluginOptions {
17+
export type AddPluginOptions<T> = MetaPlugin<T> & {
1418
how?: 'after' | 'before' | 'fixed';
1519
location?: 'top' | 'bottom' | string;
16-
}
20+
};
1721

1822
type AddPluginFn = (plugins: MetaPlugin[]) => MetaPlugin[];
1923

20-
export type AddPluginType = <F>(
21-
metaPluginAndOptions: MetaPlugin<F> & AddPluginOptions,
22-
) => AddPluginFn;
24+
export type AddPluginType = <F>(metaPluginAndOptions: AddPluginOptions<F>) => AddPluginFn;

0 commit comments

Comments
 (0)