Skip to content

Commit

Permalink
fix typo, docs for utility types
Browse files Browse the repository at this point in the history
  • Loading branch information
sfishel18 committed Apr 14, 2024
1 parent dc1d05b commit c3b4a2e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/sustainable-web-design.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
36 changes: 35 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>} Object
* @typedef {{
* [K in Exclude<keyof Object, symbol> as `${K} - first`]: Object[K]
* } & {
* [K in Exclude<keyof Object, symbol> as `${K} - subsequest`]: Object[K]
* [K in Exclude<keyof Object, symbol> 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<string, unknown>} Object
* @typedef {{
* [K in Extract<keyof Object, string> as import('type-fest').Replace<K, 'Energy', 'CO2'>]: Object[K]
Expand Down

0 comments on commit c3b4a2e

Please sign in to comment.