79215695

Date: 2024-11-22 15:57:31
Score: 7.5 🚩
Natty: 6.5
Report link

@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!!!!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): appreciated
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (3): Thanks in advance
  • RegEx Blacklisted phrase (1): I get this error
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @jcalz
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: Luigino