diff --git a/types/vscode-notebook-renderer/OTHER_FILES.txt b/types/vscode-notebook-renderer/OTHER_FILES.txt new file mode 100644 index 000000000000000..31e6de50c4e09b2 --- /dev/null +++ b/types/vscode-notebook-renderer/OTHER_FILES.txt @@ -0,0 +1 @@ +preload.d.ts diff --git a/types/vscode-notebook-renderer/events.d.ts b/types/vscode-notebook-renderer/events.d.ts new file mode 100644 index 000000000000000..2963f36732c9b90 --- /dev/null +++ b/types/vscode-notebook-renderer/events.d.ts @@ -0,0 +1,7 @@ +export interface Disposable { + dispose(): void; +} + +export interface VSCodeEvent { + (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable; +} diff --git a/types/vscode-notebook-renderer/index.d.ts b/types/vscode-notebook-renderer/index.d.ts index a1a8f9d07ca743a..a7c3a58df068589 100644 --- a/types/vscode-notebook-renderer/index.d.ts +++ b/types/vscode-notebook-renderer/index.d.ts @@ -4,15 +4,9 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Minimum TypeScript Version: 3.0 -// todo: update "Project" link above to docs site, once it becomes available +import { VSCodeEvent } from './events'; -export interface Disposable { - dispose(): void; -} - -export interface VSCodeEvent { - (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable; -} +export * from './events'; /** * Notebook output event -- a supertype of the `NotebookCellOutputItem` in the VS Code types. @@ -29,13 +23,6 @@ export interface NotebookOutputEventParams { export interface NotebookRendererApi { setState(value: T): void; getState(): T | undefined; - - /** - * Sends a message to the renderer extension code. Can be received in - * the `onDidReceiveMessage` event in `NotebookCommunication`. - */ - postMessage(msg: unknown): void; - /** * Fired before an output is destroyed, with its output ID, or undefined if * all cells are about to unmount. @@ -48,12 +35,6 @@ export interface NotebookRendererApi { * API, and `onWillDestroyOutput`. */ onDidCreateOutput: VSCodeEvent; - - /** - * Called when the renderer uses `postMessage` on the NotebookCommunication - * instance for this renderer. - */ - onDidReceiveMessage: VSCodeEvent; } declare global { diff --git a/types/vscode-notebook-renderer/preload.d.ts b/types/vscode-notebook-renderer/preload.d.ts new file mode 100644 index 000000000000000..36bb7c58bc81fd7 --- /dev/null +++ b/types/vscode-notebook-renderer/preload.d.ts @@ -0,0 +1,6 @@ +import { VSCodeEvent } from './events'; + +declare global { + const onDidReceiveKernelMessage: VSCodeEvent; + function postKernelMessage(data: unknown): void; +} diff --git a/types/vscode-notebook-renderer/vscode-notebook-renderer-tests.ts b/types/vscode-notebook-renderer/vscode-notebook-renderer-tests.ts index 2f1f5c0c544b865..b036abdf20c3801 100644 --- a/types/vscode-notebook-renderer/vscode-notebook-renderer-tests.ts +++ b/types/vscode-notebook-renderer/vscode-notebook-renderer-tests.ts @@ -26,14 +26,16 @@ const listener = notebookApi.onDidCreateOutput(({ element, outputId, value, mime listener.dispose(); -notebookApi.onDidReceiveMessage(msg => { - // $ExpectType any - msg; - - notebookApi.postMessage(msg); -}); - notebookApi.onWillDestroyOutput(evt => { // $ExpectType { outputId: string; } | undefined evt; }); + +import 'vscode-notebook-renderer/preload'; + +onDidReceiveKernelMessage(msg => { + // $ExpectType any + msg; + + postKernelMessage(msg); +});