Type markdown preview webview message (#176444)

Simply types messages. Will clean up types in next pass
This commit is contained in:
Matt Bierner
2023-03-07 14:23:17 -08:00
committed by GitHub
parent 9c7113f6ae
commit 6a44101bb1
4 changed files with 106 additions and 57 deletions

View File

@@ -4,17 +4,24 @@
*--------------------------------------------------------------------------------------------*/
import { SettingsManager } from './settings';
import type { FromWebviewMessage } from '../types/previewMessaging';
export interface MessagePoster {
/**
* Post a message to the markdown extension
*/
postMessage(type: string, body: object): void;
postMessage<T extends FromWebviewMessage.Type>(
type: T['type'],
body: Omit<T, 'source' | 'type'>
): void;
}
export const createPosterForVsCode = (vscode: any, settingsManager: SettingsManager) => {
return new class implements MessagePoster {
postMessage(type: string, body: object): void {
export const createPosterForVsCode = (vscode: any, settingsManager: SettingsManager): MessagePoster => {
return {
postMessage<T extends FromWebviewMessage.Type>(
type: T['type'],
body: Omit<T, 'source' | 'type'>
): void {
vscode.postMessage({
type,
source: settingsManager.settings!.source,