Closed mgriffin-scottlogic closed 5 months ago
yes i think you would need to make a pull request to DefinitelyTyped to fix it. and in the meantime you could do something like this locally:
interface CO2EstimateComponents {
consumerDeviceCO2: number;
networkCO2: number;
dataCenterCO2: number;
productionCO2: number;
total: number;
}
const co2Emission = new co2({
results: "segment",
});
const bytesSent = 1000 * 1000 * 1000;
const greenHost = false;
const estimatedCO2 = co2Emission.perByte(bytesSent, greenHost) as unknown as CO2EstimateComponents;
console.log(estimatedCO2.networkCO2);
@mgriffin-scottlogic thanks, please do submit a PR to update the JSDoc comments. To update the types, please do update the DefinitelyTyped project definitions.
Closing this as the updates have been merged into the DefinitelyTyped project.
Describe the bug The CO2 class has an option in code to segment the results when using the default SustainableWebDesign model. However the documentation and types do not reflect this, making it difficult to access cleanly.
To Reproduce Construct the CO2 class like so:
Make a per byte estimation:
Unable to access the individual components of the result:
Expected behavior A type/typedef along the lines of:
Is defined and the return types are changed to be a union of number and this type.
Environment (please complete the following information):
Additional context (if applicable) Not sure if this is intentional and the ability to segment results should not be exposed?
I would like to use this mode to extract the network CO2 emissions separately from the total. I have a fork with changes to the JSDoc types, I assume to change the Typescript definitions I would need to make a pull request to the DefinitelyTyped repo?