node.jsmendix

Mendix setup problem - suggested code not working


I'm dipping my toe into Mendix Typescript SDK and followed the instructions on https://docs.mendix.com/apidocs-mxsdk/mxsdk/setting-up-your-development-environment.

I then followed https://docs.mendix.com/apidocs-mxsdk/mxsdk/creating-your-first-script to create a script to try it out.

However, I'm getting the following error to the code script.ts suggested on this page:

error TS2554: Expected 1-2 arguments, but got 0.
30     return dm.load();
      ~~~~~~~~~
node_modules/mendixmodelsdk/dist/gen/domainmodels.d.ts:583:14
583         load(callback: (element: DomainModel) => void, forceRefresh?: boolean): void;
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An argument for 'callback' was not provided.
Found 1 error.

return dm.load();

I'm not NodeJS savvy - but I can tell the parameter passed in to load() is incorrect - just doesn't exists although load() is defined to take a parameter. But then, why the error to a script on the suggested setup? I'll attack this issue. But need help on where to start.

This "feels" like a version difference/setup error. But I've seen no errors anywhere else while I was setting it up.

What am i missing?


Solution

  • I don't have experience in making that particular example script work; it might as well be out of date. In my own script, I'm loading the data model with the loadAsPromise function, as indicated in the script in the article Generate Code from the Model.

    async function serializeToJs() {
        const workingCopy = await project.createWorkingCopy();
        const domainModelInterface = workingCopy.model().allDomainModels().filter(dm => dm.containerAsModule.name === moduleName)[0];
    
        try {
            const domainModel = await loadAsPromise(domainModelInterface);
            console.log(JavaScriptSerializer.serializeToJs(domainModel)); //print out the generated JavaScript
            console.log("success!")
        } catch (error) {
            console.log(`error: ${error}`);
        }
    }