|
@@ -523,23 +523,19 @@ namespace Private {
|
|
|
return extender;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * A type that corersponds to the string properties of the generic T (e.g., 'noun')
|
|
|
- */
|
|
|
- type StringProps<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];
|
|
|
-
|
|
|
- type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
|
|
-
|
|
|
/**
|
|
|
* A utility function that delegates a portion of a label to an IMenuExtender.
|
|
|
*/
|
|
|
export
|
|
|
- function delegateLabel<E extends IMenuExtender<Widget>>(app: JupyterLab, s: Set<E>, label: StringProps<E>): string {
|
|
|
+ function delegateLabel<E extends IMenuExtender<Widget>>(app: JupyterLab, s: Set<E>, label: keyof E): string {
|
|
|
let widget = app.shell.currentWidget;
|
|
|
const extender = findExtender(widget, s);
|
|
|
if (!extender) {
|
|
|
return '';
|
|
|
}
|
|
|
+ // Coerce the result to be a string. When Typedoc is updated to use
|
|
|
+ // Typescript 2.8, we can possibly use conditional types to get Typescript
|
|
|
+ // to recognize this is a string.
|
|
|
return extender[label] as any as string;
|
|
|
}
|
|
|
|
|
@@ -548,13 +544,16 @@ namespace Private {
|
|
|
* to an IMenuExtender.
|
|
|
*/
|
|
|
export
|
|
|
- function delegateExecute<E extends IMenuExtender<Widget>>(app: JupyterLab, s: Set<E>, executor: FunctionPropertyNames<E>): () => Promise<any> {
|
|
|
+ function delegateExecute<E extends IMenuExtender<Widget>>(app: JupyterLab, s: Set<E>, executor: keyof E): () => Promise<any> {
|
|
|
return () => {
|
|
|
let widget = app.shell.currentWidget;
|
|
|
const extender = findExtender(widget, s);
|
|
|
if (!extender) {
|
|
|
return Promise.resolve(void 0);
|
|
|
}
|
|
|
+ // Coerce the result to be a function. When Typedoc is updated to use
|
|
|
+ // Typescript 2.8, we can possibly use conditional types to get Typescript
|
|
|
+ // to recognize this is a function.
|
|
|
let f = extender[executor] as any as (w: Widget) => Promise<any>;
|
|
|
return f(widget);
|
|
|
};
|
|
@@ -583,7 +582,10 @@ namespace Private {
|
|
|
return () => {
|
|
|
let widget = app.shell.currentWidget;
|
|
|
const extender = findExtender(widget, s);
|
|
|
- return !!extender && !!extender[toggled] && !!(extender[toggled] as any as (w: Widget) => boolean)(widget);
|
|
|
+ // Coerce extender[toggled] to be a function. When Typedoc is updated to use
|
|
|
+ // Typescript 2.8, we can possibly use conditional types to get Typescript
|
|
|
+ // to recognize this is a function.
|
|
|
+ return !!extender && !!extender[toggled] && !!(extender[toggled] as any as (w: Widget) => (() => boolean))(widget);
|
|
|
};
|
|
|
}
|
|
|
}
|