Skip to content

Commit

Permalink
fix: changed ConfigInstance to depends on type instead of on schema
Browse files Browse the repository at this point in the history
  • Loading branch information
CptSchnitz committed Jun 27, 2024
1 parent 6b9a2ae commit 86de770
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const arrayMerge: deepmerge.Options['arrayMerge'] = (destinationArray, sourceArr
* @param {ConfigOptions<T>} options - The options for retrieving the configuration.
* @returns {Promise<ConfigInstance<T>>} - A promise that resolves to the configuration object.
*/
export async function config<T extends { [typeSymbol]: unknown; $id?: string }>(options: ConfigOptions<T>): Promise<ConfigInstance<T>> {
export async function config<T extends { [typeSymbol]: unknown; $id?: string }>(
options: ConfigOptions<T>
): Promise<ConfigInstance<T[typeof typeSymbol]>> {
// handle package options
debug('config called with options: %j', options);
const { schema: baseSchema, ...unvalidatedOptions } = options;
Expand Down Expand Up @@ -104,7 +106,7 @@ export async function config<T extends { [typeSymbol]: unknown; $id?: string }>(
return lodash.get(validatedConfig as (typeof baseSchema)[typeof typeSymbol], path);
}

function getAll(): ReturnType<ConfigInstance<T>['getAll']> {
function getAll(): ReturnType<ConfigInstance<T[typeof typeSymbol]>['getAll']> {
debug('getAll called');
return validatedConfig;
}
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ export const optionsSchema: JSONSchemaType<BaseOptions> = {
* Represents the schema of the configuration object.
* @template T - The type of the configuration schema.
*/
export interface ConfigInstance<T extends SchemaWithType> {
export interface ConfigInstance<T> {
/**
* Retrieves the value at the specified path from the configuration object.
* @template TPath - The type of the path.
* @param path - The path to the desired value.
* @returns The value at the specified path.
*/
get: <TPath extends string>(path: TPath) => _.GetFieldType<T[typeof typeSymbol], TPath>;
get: <TPath extends string>(path: TPath) => _.GetFieldType<T, TPath>;

/**
* Retrieves the entire configuration object.
* @returns The entire configuration object.
*/
getAll: () => T[typeof typeSymbol];
getAll: () => T;

/**
* Retrieves different parts of the configuration object before being merged and validated.
Expand Down

0 comments on commit 86de770

Please sign in to comment.