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 fbbeabf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
25 changes: 0 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GLOBAL_GRID_INTENSITY,
RENEWABLES_GRID_INTENSITY,
} from "./constants/index.js";
import { parseOptions, toTotalCO2 } from "./helpers/index.js";
import { parseOptions } from "./helpers/index.js";

class CO2 {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/hosting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ const jsonPath = path.resolve(
);

describe("hosting", () => {
/** @type {unknown} */
let har;
/** @type {jest.SpyInstance<typeof https['get']>} */
let httpsGetSpy;
beforeEach(() => {
// @ts-ignore
httpsGetSpy = jest.spyOn(https, "get");
jest.clearAllMocks();
});
Expand Down
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 fbbeabf

Please sign in to comment.