@types/config 3.3.3 → 3.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
config/README.md CHANGED
@@ -8,8 +8,8 @@ This package contains type definitions for config (https://github.com/lorenwest/
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/config.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Mon, 06 Nov 2023 22:41:05 GMT
11
+ * Last updated: Tue, 03 Sep 2024 23:36:04 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
15
- These definitions were written by [Roman Korneev](https://github.com/RWander), [Forrest Bice](https://github.com/forrestbice), [James Donald](https://github.com/jndonald3), [Alberto Vasquez](https://github.com/albertovasquez), and [Christian Vaagland Tellnes](https://github.com/tellnes).
15
+ These definitions were written by [Roman Korneev](https://github.com/RWander), [Forrest Bice](https://github.com/forrestbice), [James Donald](https://github.com/jndonald3), [Alberto Vasquez](https://github.com/albertovasquez), [Christian Vaagland Tellnes](https://github.com/tellnes), and [Paritosh Bhatia](https://github.com/ParitoshBh).
config/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ConfigPaths, ConfigPathValues, HasBeenAugmented } from "./utils";
2
+
1
3
  declare var c: c.IConfig;
2
4
 
3
5
  declare namespace c {
@@ -11,6 +13,9 @@ declare namespace c {
11
13
  // Return a deep copy of the specified object.
12
14
  cloneDeep(copyFrom: any, depth?: number): any;
13
15
 
16
+ // Set objects given a path as a string list
17
+ setPath(object: object, path: string[], value?: any): void;
18
+
14
19
  // Return true if two objects have equal contents.
15
20
  equalsDeep(object1: any, object2: any, dept?: number): boolean;
16
21
 
@@ -42,8 +47,34 @@ declare namespace c {
42
47
  setModuleDefaults(moduleName: string, defaults: any): any;
43
48
  }
44
49
 
50
+ /**
51
+ * By augmenting this interface with your own config, you can greatly improve the IntelliSense for the `get` method:
52
+ * - Dot notation paths for the `setting` parameter
53
+ * - Correctly typed return values
54
+ *
55
+ * @example
56
+ * declare module 'config' {
57
+ * interface IConfig extends MyConfig {}
58
+ * }
59
+ *
60
+ * @example
61
+ * declare module 'config' {
62
+ * interface IConfig {
63
+ * myConfig: {
64
+ * myString: string;
65
+ * myNumber: number;
66
+ * };
67
+ * }
68
+ * }
69
+ *
70
+ * @example
71
+ * const knownToBeStringTyped = config.get('myConfig.myString');
72
+ */
45
73
  interface IConfig {
46
- get<T>(setting: string): T;
74
+ get: HasBeenAugmented<IConfig> extends true
75
+ ? <T extends ConfigPaths<IConfig>>(setting: T) => ConfigPathValues<IConfig, T>
76
+ : <T>(setting: string) => T;
77
+ has(setting: ConfigPaths<IConfig>): boolean;
47
78
  has(setting: string): boolean;
48
79
  util: IUtil;
49
80
  }
config/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/config",
3
- "version": "3.3.3",
3
+ "version": "3.3.5",
4
4
  "description": "TypeScript definitions for config",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/config",
6
6
  "license": "MIT",
@@ -29,6 +29,11 @@
29
29
  "name": "Christian Vaagland Tellnes",
30
30
  "githubUsername": "tellnes",
31
31
  "url": "https://github.com/tellnes"
32
+ },
33
+ {
34
+ "name": "Paritosh Bhatia",
35
+ "githubUsername": "ParitoshBh",
36
+ "url": "https://github.com/ParitoshBh"
32
37
  }
33
38
  ],
34
39
  "main": "",
@@ -40,6 +45,6 @@
40
45
  },
41
46
  "scripts": {},
42
47
  "dependencies": {},
43
- "typesPublisherContentHash": "6209b0a13db5f48492293400c4c02c56d7f7a27060887c348741fd6ecc3032b1",
44
- "typeScriptVersion": "4.5"
48
+ "typesPublisherContentHash": "6b0a351b5b0630d58f027161bcf83523c39ecda3d5c25865e3fd51d5ae3b1789",
49
+ "typeScriptVersion": "4.8"
45
50
  }
config/utils.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}`
2
+ : never
3
+ : never;
4
+
5
+ export type ConfigPaths<T> = T extends object ? {
6
+ [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, ConfigPaths<T[K]>>
7
+ : never;
8
+ }[keyof T]
9
+ : "";
10
+
11
+ export type ConfigPathValues<O, P extends string> = P extends `${infer K}.${infer Rest}`
12
+ ? K extends keyof O ? ConfigPathValues<O[K], Rest>
13
+ : never
14
+ : P extends keyof O ? O[P]
15
+ : never;
16
+
17
+ type IsSubsetOf<T, U> = T extends U ? true : false;
18
+
19
+ export type HasBeenAugmented<T> = IsSubsetOf<Exclude<keyof T, "get" | "has" | "util">, never> extends true ? false
20
+ : true;