@@ -35,7 +35,7 @@ export type PostMessageListener<T> = (data: T) => void | Promise<void>;
3535 * The vscode api for post message
3636 */
3737class VSCodeWebview {
38- private readonly webviewApi : WebviewApi < unknown > | undefined ;
38+ private readonly webviewApi : WebviewApi < any > | undefined ;
3939 private _options : PostMessageOptions = {
4040 interval : INTERVAL ,
4141 timeout : TIMEOUT ,
@@ -138,10 +138,19 @@ class VSCodeWebview {
138138 } ) ;
139139 }
140140
141+ /**
142+ * Register a listener for a message type
143+ * @param type the message type
144+ * @param listener the listener
145+ */
141146 on < T > ( type : string , listener : PostMessageListener < T > ) {
142147 this . listeners . set ( type , listener ) ;
143148 }
144149
150+ /**
151+ * Remove a listener for a message type
152+ * @param type the message type
153+ */
145154 off ( type : string ) {
146155 this . listeners . delete ( type ) ;
147156 }
@@ -151,7 +160,7 @@ class VSCodeWebview {
151160 *
152161 * @return The current state or `undefined` if no state has been set.
153162 */
154- async getState ( ) : Promise < any > {
163+ async getState < T = any > ( ) : Promise < T > {
155164 return this . webviewApi ?. getState ( ) ;
156165 }
157166
@@ -170,6 +179,11 @@ class VSCodeWebview {
170179}
171180
172181/**
173- * the vscode webview api
182+ * The vscode webview api
174183 */
175184export const vscodeWebview = new VSCodeWebview ( ) ;
185+
186+ /**
187+ * The vscode webview api
188+ */
189+ export const webviewApi = vscodeWebview ;
0 commit comments