Add explicit return type to convertToLegacyModeledMethod

This commit is contained in:
Koen Vlaswinkel
2023-10-10 09:26:27 +02:00
parent b76369330d
commit 54e1b29940
2 changed files with 19 additions and 8 deletions

View File

@@ -150,10 +150,13 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
if (this.webviewView && e.isActiveDb) {
const modeledMethods = e.modeledMethods[this.method?.signature ?? ""];
if (modeledMethods) {
await this.postMessage({
t: "setModeledMethod",
method: convertToLegacyModeledMethod(modeledMethods),
});
const modeledMethod = convertToLegacyModeledMethod(modeledMethods);
if (modeledMethod) {
await this.postMessage({
t: "setModeledMethod",
method: modeledMethod,
});
}
}
}
}),

View File

@@ -37,9 +37,15 @@ export function convertToLegacyModeledMethods(
): Record<string, ModeledMethod> {
// Always take the first modeled method in the array
return Object.fromEntries(
Object.entries(modeledMethods).map(([signature, modeledMethods]) => {
return [signature, convertToLegacyModeledMethod(modeledMethods)];
}),
Object.entries(modeledMethods)
.map(([signature, modeledMethods]) => {
const modeledMethod = convertToLegacyModeledMethod(modeledMethods);
if (!modeledMethod) {
return null;
}
return [signature, modeledMethod];
})
.filter((entry): entry is [string, ModeledMethod] => entry !== null),
);
}
@@ -66,6 +72,8 @@ export function convertFromLegacyModeledMethod(modeledMethod: ModeledMethod) {
*
* @param modeledMethods The ModeledMethod[]
*/
export function convertToLegacyModeledMethod(modeledMethods: ModeledMethod[]) {
export function convertToLegacyModeledMethod(
modeledMethods: ModeledMethod[],
): ModeledMethod | undefined {
return modeledMethods[0];
}