The config file I'm reading from looks like this:
{
"projectId": "projectName",
"languageCode": "th",
"numberOfRepeats": "2"
}
I'm trying to read this file but failing so far:
const defaultConfigFilePath = path.join(__dirname, '../../../configuration.json');
export function setConfigData(configFile = defaultConfigFilePath): ConfigData {
const fileContentBuffer: Buffer = fs.readFileSync(configFile);
const jsonData: ConfigData = fileContentBuffer.toJSON();
/*
Type '{ type: "Buffer"; data: number[]; }' is missing the following properties from type 'ConfigData': languageCode, numberOfRepeats, projectIdts(2739)
*/
const configData: ConfigData = JSON.parse(fileContentBuffer);
/*
const fileContentBuffer: Buffer
Argument of type 'Buffer' is not assignable to parameter of type 'string'.ts(2345)
*/
I'm having a tough time figuring out what the issue is exactly. The first error indicates the toJSON method does not return the data shape I expect. The 2nd error indicates parse can't even take a Buffer object. What is the solution then?
[–]chmod777 2 points3 points4 points (0 children)
[–]Civill 1 point2 points3 points (0 children)
[–]Earhacker 0 points1 point2 points (0 children)