0

I have this issue in TypeScript:

import axios from "axios";
import Papa from "papaparse";
axios.get("www.../data.csv").then(function (csvdata) {
    const csvString = csvdata.data;
    const parsed = Papa.parse(csvString, {
        header: true,
        dynamicTyping: true,
        fastMode: true,
    });
    export const jsonData = parsed.data;
});

I tried to export const jsonData = parsed.data; , but it doesn't compile (error: TS1184). I need some insights into a possible solution. Regards.

spender
  • 117,338
  • 33
  • 229
  • 351
Aoguzie
  • 35
  • 9
  • 1
    why not export the request as a function to make it callable elsewhere? something like this: `export const xxx = () => axios.get(....` – Ric Jul 08 '21 at 13:15
  • You can't export data that the compiler can't read and get the type of. TypeScript, as far as I know, can't read a CSV and get the types of the objects that might be produced from it (hence the use of "papaparse"). So, if you know the types that papaparse eventually will create from that CSV, export a promise of that type. – Heretic Monkey Jul 08 '21 at 13:16
  • 1
    Does this answer your question? [Javascript/Typescript Export Default Const as value from async function call](https://stackoverflow.com/questions/65589922/javascript-typescript-export-default-const-as-value-from-async-function-call) – Heretic Monkey Jul 08 '21 at 13:22

0 Answers0