@types/config 3.3.4 → 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,7 +8,7 @@ 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: Thu, 21 Mar 2024 20:35:57 GMT
11
+ * Last updated: Tue, 03 Sep 2024 23:36:04 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
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 {
@@ -45,8 +47,34 @@ declare namespace c {
45
47
  setModuleDefaults(moduleName: string, defaults: any): any;
46
48
  }
47
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
+ */
48
73
  interface IConfig {
49
- 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;
50
78
  has(setting: string): boolean;
51
79
  util: IUtil;
52
80
  }
config/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/config",
3
- "version": "3.3.4",
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",
@@ -45,6 +45,6 @@
45
45
  },
46
46
  "scripts": {},
47
47
  "dependencies": {},
48
- "typesPublisherContentHash": "c48f0669147a8a94900327fa9c6f0d6a850de6901a30787160f0071a6eeab8db",
49
- "typeScriptVersion": "4.7"
48
+ "typesPublisherContentHash": "6b0a351b5b0630d58f027161bcf83523c39ecda3d5c25865e3fd51d5ae3b1789",
49
+ "typeScriptVersion": "4.8"
50
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;