@jcalz , following your solution in my scenario I have this:
Element.tsx
(as independent component where I get elements from a Kotlin local library module)
export {};
import {getExternalElements} from "externallibrary";
import {useEffect, useState} from "react";
interface Element {
Id: string
State: boolean
Name: string
Address: string
}
export namespace NamespaceElements {
export class Elements {
elementsResult: Array<Element> = [];
constructor() { this.refreshElements() }
refreshElements() {
const [elements_json, setElements] = useState<string | null>(null);
useEffect(() => {
getExternalElements().then(result => {
setElements(result.toString());
})
}, []);
this.elementsResult = JSON.parse(elements_json?.toString() as string)
}
getElementsJsonString() {
return JSON.stringify(this.elementsResult).toString();
}
}
}
declare global {
namespace globalThis {
export import Elements = NamespaceElements.Elements;
}
}
Object.assign(globalThis, NamespaceElements);
which I declare globally in declaration.d.ts
, so it won't need any import when called, as :
declare module "./src/components/Elements/Elements" {
import NamespaceElements from "./src/components/Elements/Elements";
const Elements : NamespaceElements.Elements;
export default Elements;
}
but if in frontend.tsx
where I need to refresh and retrieve having this useEffect:
const [elementJsonString, setElements] = useState<string | null>(null);
useEffect(() => {
Elements.refreshElements()
const elemsString = Elements.getElementsJsonString()
setIpAddress( elemsString.toString() )
}, []);
I get this error TS2339: Property refreshElements does not exist on type typeof Element
.... since I am correctly exporting that class following your scenario , why it doesn't get calling corretly those functions? A suggest is appreciated... maybe I confused something....
Thanks in advance!!!!