reactjsxmltypescriptblockly

How to read xml file(toolsbox.xml) in React typescript


I am unable to import xml file in tsx file, but in jsx file i can able to access that xml file

enter image description here

enter image description here


Solution

  • You need to define a module for typescript to evaluate, otherwise it will try to look for something like toolbox.xml.ts.

    Something along these lines in a file called XML.d.ts (for this placed in a folder @types in src):

    declare module "*.xml" {
      const doc: any; // Change this to an actual XML type
      export default doc;
    }
    

    and add "typeRoots": ["src/@types", "node_modules/@types"] to your tsconfig.json (this makes typescript pick up the new typings file along with all installed types).