File tree 4 files changed +37
-3
lines changed
4 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 1
- export declare namespace Base {
2
- type Options = {
1
+ export namespace Base {
2
+ interface Options {
3
3
[ key : string ] : unknown ;
4
- } ;
4
+ }
5
5
}
6
6
7
7
declare type ApiExtension = {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Base } from "./index.js";
4
4
import { fooPlugin } from "./plugins/foo/index.js" ;
5
5
import { barPlugin } from "./plugins/bar/index.js" ;
6
6
import { voidPlugin } from "./plugins/void/index.js" ;
7
+ import { withOptionsPlugin } from "./plugins/with-options" ;
7
8
8
9
const base = new Base ( ) ;
9
10
@@ -48,3 +49,8 @@ expectType<string>(baseWithVoidAndNonVoidPlugins.bar);
48
49
49
50
// @ts -expect-error unknown properties cannot be used, see #31
50
51
baseWithVoidAndNonVoidPlugins . unknown ;
52
+
53
+ const BaseWithOptionsPlugin = Base . plugin ( withOptionsPlugin ) ;
54
+ const baseWithOptionsPlugin = new BaseWithOptionsPlugin ( ) ;
55
+
56
+ expectType < string > ( baseWithOptionsPlugin . getFooOption ( ) ) ;
Original file line number Diff line number Diff line change
1
+ // https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html
2
+ import { Base } from "../.." ;
3
+
4
+ declare module "../.." {
5
+ namespace Base {
6
+ interface Options {
7
+ foo ?: string ;
8
+ }
9
+ }
10
+ }
11
+
12
+ export function withOptionsPlugin (
13
+ base : Base ,
14
+ options : Base . Options
15
+ ) : {
16
+ getFooOption : ( ) => Required < Base . Options > [ "foo" ] ;
17
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {import('../..').Base } base
3
+ * @param {import('../..').Base.Options } options
4
+ */
5
+ export function withOptionsPlugin ( base , options ) {
6
+ return {
7
+ getFooOption ( ) {
8
+ return options . foo || "my default" ;
9
+ } ,
10
+ } ;
11
+ }
You can’t perform that action at this time.
0 commit comments