Browse Source

Fix typedoc errors

Jason Grout 7 years ago
parent
commit
e416182c0f

+ 12 - 10
packages/mainmenu-extension/src/index.ts

@@ -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);
     };
   }
 }

+ 1 - 1
packages/metapackage/package.json

@@ -26,7 +26,7 @@
   "scripts": {
     "build": "tsc && node build.js",
     "clean": "rimraf lib",
-    "docs": "typedoc --mode modules --module commonjs --excludeNotExported --target es5 --moduleResolution node --name JupyterLab --out ../../docs/api .",
+    "docs": "typedoc --mode modules --module commonjs --excludeNotExported --target es2015 --moduleResolution node --name JupyterLab --out ../../docs/api .",
     "prepublishOnly": "npm run build",
     "watch": "tsc -w",
     "watch:files": "node watch-files.js"

+ 34 - 0
packages/metapackage/src/typings.d.ts

@@ -6,3 +6,37 @@
 /// <reference path="../../coreutils/typings/url-parse/url-parse.d.ts"/>
 /// <reference path="../../terminal/typings/xterm/xterm.d.ts"/>
 /// <reference path="../../vdom-extension/src/transform-vdom.d.ts"/>
+
+// TextEncoder interfaces for typedoc, since typedoc is still using TypeScript 2.7
+// Remove these when typedoc is updated to use TypeScript 2.8
+
+interface TextDecodeOptions {
+    stream?: boolean;
+}
+
+interface TextDecoderOptions {
+    fatal?: boolean;
+    ignoreBOM?: boolean;
+}
+
+interface TextDecoder {
+    readonly encoding: string;
+    readonly fatal: boolean;
+    readonly ignoreBOM: boolean;
+    decode(input?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | null, options?: TextDecodeOptions): string;
+}
+
+declare var TextDecoder: {
+    prototype: TextDecoder;
+    new(label?: string, options?: TextDecoderOptions): TextDecoder;
+};
+
+interface TextEncoder {
+    readonly encoding: string;
+    encode(input?: string): Uint8Array;
+}
+
+declare var TextEncoder: {
+    prototype: TextEncoder;
+    new(): TextEncoder;
+};

+ 34 - 0
packages/services/src/typedoc.d.ts

@@ -10,3 +10,37 @@
 /// <reference path="../node_modules/typescript/lib/lib.dom.d.ts"/>
 /// <reference path="../node_modules/typescript/lib/lib.es5.d.ts"/>
 /// <reference path="../node_modules/typescript/lib/lib.es2015.collection.d.ts"/>
+
+// TextEncoder interfaces for typedoc, since typedoc is still using TypeScript 2.7
+// Remove these when typedoc is updated to use TypeScript 2.8
+
+interface TextDecodeOptions {
+    stream?: boolean;
+}
+
+interface TextDecoderOptions {
+    fatal?: boolean;
+    ignoreBOM?: boolean;
+}
+
+interface TextDecoder {
+    readonly encoding: string;
+    readonly fatal: boolean;
+    readonly ignoreBOM: boolean;
+    decode(input?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | null, options?: TextDecodeOptions): string;
+}
+
+declare var TextDecoder: {
+    prototype: TextDecoder;
+    new(label?: string, options?: TextDecoderOptions): TextDecoder;
+};
+
+interface TextEncoder {
+    readonly encoding: string;
+    encode(input?: string): Uint8Array;
+}
+
+declare var TextEncoder: {
+    prototype: TextEncoder;
+    new(): TextEncoder;
+};

+ 1 - 1
packages/services/typedoc.json

@@ -2,7 +2,7 @@
   "mode": "file",
   "module": "commonjs",
   "excludeNotExported": true,
-  "target": "es5",
+  "target": "es2015",
   "moduleResolution": "node",
   "out": "docs/",
   "excludeExternals": "true",