From c3b4a2e9f450ed764dd117d1a6e1fd1f329b4b0d Mon Sep 17 00:00:00 2001 From: Simon Fishel Date: Sun, 24 Mar 2024 20:40:48 -0700 Subject: [PATCH] fix typo, docs for utility types --- src/sustainable-web-design.js | 1 - src/types.js | 36 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/sustainable-web-design.js b/src/sustainable-web-design.js index d03801f..7d68f83 100644 --- a/src/sustainable-web-design.js +++ b/src/sustainable-web-design.js @@ -176,7 +176,6 @@ class SustainableWebDesign { segmentResults = false, options = undefined ) { - // TODO (simon) figure out if this method call is correct const energyBycomponent = this.energyPerVisitByComponent(bytes, options); if (typeof carbonIntensity !== "boolean") { diff --git a/src/types.js b/src/types.js index f9e8447..45f9909 100644 --- a/src/types.js +++ b/src/types.js @@ -140,15 +140,49 @@ */ /** + * Utility type to create "- first" and "- subsequent" variants of each key in the incoming type. + * + * Ex. for this input type: + * + * { + * keyOne: number, + * keyTwo: number + * } + * + * The output type will be: + * + * { + * "keyOne - first": number, + * "keyOne - subsequent": number, + * "keyTwo - first": number, + * "keyTwo - subsequent": number, + * } + * * @template {Record} Object * @typedef {{ * [K in Exclude as `${K} - first`]: Object[K] * } & { - * [K in Exclude as `${K} - subsequest`]: Object[K] + * [K in Exclude as `${K} - subsequent`]: Object[K] * }} SegmentedByVisit */ /** + * Utility type to convert keys from representations of energy to representations of CO2. + * + * Ex. for this input type: + * + * { + * keyOneEnergy: number, + * keyTwoEnergy: number + * } + * + * The output type will be: + * + * { + * keyOneCO2: number, + * keyTwoCO2: number + * } + * * @template {Record} Object * @typedef {{ * [K in Extract as import('type-fest').Replace]: Object[K]