unyt-org / uix

The UIX Framework
https://uix.unyt.org
MIT License
54 stars 3 forks source link

Automatic lazy loading of JS type definition modules from frontend #56

Open benStre opened 8 months ago

benStre commented 8 months ago

Currently, when a DATEX value with a corresponding JS module (e.g. containing a @sync class) ist sent from the backend to the frontend, the JS module url is automatically appended to the DATEX request so that the JS type class is initialized on the frontend.

This does currently not work when a DATEX value that requires a JS sync class module is sent from the frontend to the backend.

If we have a module like this on the backend, and MySyncClass is not used anywhere else in the backend, it will never be initialized at runtime because it is only regarded as a TypeScript type definition:

// file: backend/do-something.ts
import { MySyncClass } from "common/sync-class.ts";

export function doSomething(syncClass: MySyncClass) {
    // ...
}

When the function is now called from the frontend with an instance of MySyncClass, we get a warning on the backend:

Cannot find type definition for \<MySyncClass>

This can only be prevented if the frontend also sends the corresponding JS module URL to the backend together with the instance. This is currently explicitly disabled for the following reasons:

benStre commented 8 months ago

Current workaround:

import { MySyncClass } from "common/sync-class.ts";
import "common/sync-class.ts"; // <- add this import