@types/vscode-webview
TypeScript icon, indicating that this package has built-in type declarations

1.57.5 • Public • Published

Installation

npm install --save @types/vscode-webview

Summary

This package contains type definitions for vscode-webview (https://code.visualstudio.com/api/extension-guides/webview).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/vscode-webview.

index.d.ts

/**
 * API exposed to webviews.
 *
 * @template StateType Type of the persisted state stored for the webview.
 */
export interface WebviewApi<StateType> {
    /**
     * Post a message to the owner of the webview.
     *
     * @param message Data to post. Must be JSON serializable.
     */
    postMessage(message: unknown): void;

    /**
     * Get the persistent state stored for this webview.
     *
     * @return The current state or `undefined` if no state has been set.
     */
    getState(): StateType | undefined;

    /**
     * Set the persistent state stored for this webview.
     *
     * @param newState New persisted state. This must be a JSON serializable object. Can be retrieved
     * using {@link getState}.
     *
     * @return The new state.
     */
    setState<T extends StateType | undefined>(newState: T): T;
}

declare global {
    /**
     * Acquire an instance of the webview API.
     *
     * This may only be called once in a webview's context. Attempting to call `acquireVsCodeApi` after it has already
     * been called will throw an exception.
     *
     * @template StateType Type of the persisted state stored for the webview.
     */
    // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
    function acquireVsCodeApi<StateType = unknown>(): WebviewApi<StateType>;
}

Additional Details

  • Last updated: Tue, 30 Jan 2024 21:35:45 GMT
  • Dependencies: none

Credits

These definitions were written by Matt Bierner.

/@types/vscode-webview/

    Package Sidebar

    Install

    npm i @types/vscode-webview

    Weekly Downloads

    29,977

    Version

    1.57.5

    License

    MIT

    Unpacked Size

    5.25 kB

    Total Files

    5

    Last publish

    Collaborators

    • types