Skip to content

Commit 7991d52

Browse files
committed
chore: update types
1 parent 172382f commit 7991d52

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

lib/loader/dotenv-loader.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export interface DotenvLoaderOptions {
8282
}
8383

8484
const loadEnvFile = (options: DotenvLoaderOptions): Record<string, any> => {
85-
const dotenv = loadPackage('dotenv', 'dotenvLoader', () => require('dotenv'));
85+
const dotenv = loadPackage<Awaited<typeof import('dotenv')>>(
86+
'dotenv',
87+
'dotenvLoader',
88+
() => require('dotenv'),
89+
);
8690
const envFilePaths = Array.isArray(options.envFilePath)
8791
? options.envFilePath
8892
: [options.envFilePath || resolve(process.cwd(), '.env')];
@@ -95,10 +99,10 @@ const loadEnvFile = (options: DotenvLoaderOptions): Record<string, any> => {
9599
config,
96100
);
97101
if (options.expandVariables) {
98-
const dotenvExpand = loadPackage(
99-
'dotenv-expand',
100-
"dotenvLoader's ability to expandVariables",
101-
() => require('dotenv-expand'),
102+
const dotenvExpand = loadPackage<
103+
Awaited<typeof import('dotenv-expand')>
104+
>('dotenv-expand', "dotenvLoader's ability to expandVariables", () =>
105+
require('dotenv-expand'),
102106
);
103107
config = dotenvExpand.expand({ parsed: config }).parsed!;
104108
}

lib/loader/file-loader.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { loadPackage } from '../utils/load-package.util';
66
const DEFAULT_VALUE_SEPARATOR = ':-';
77

88
const loadToml = function loadToml(filepath: string, content: string) {
9-
const parseToml = loadPackage(
9+
const parseToml = loadPackage<Awaited<typeof import('@iarna/toml')>>(
1010
'@iarna/toml',
1111
"fileLoader's ability to parse TOML files",
1212
() => require('@iarna/toml'),
@@ -85,8 +85,10 @@ const getSearchOptions = (options: FileLoaderOptions) => {
8585
export const fileLoader = (
8686
options: FileLoaderOptions = {},
8787
): (() => Record<string, any>) => {
88-
const cosmiconfig = loadPackage('cosmiconfig', 'fileLoader', () =>
89-
require('cosmiconfig'),
88+
const cosmiconfig = loadPackage<Awaited<typeof import('cosmiconfig')>>(
89+
'cosmiconfig',
90+
'fileLoader',
91+
() => require('cosmiconfig'),
9092
);
9193

9294
const { cosmiconfigSync } = cosmiconfig;
@@ -100,7 +102,7 @@ export const fileLoader = (
100102
searchPlaces,
101103
...options,
102104
loaders,
103-
transform: (result: Record<string, any> | null) => {
105+
transform: result => {
104106
if (
105107
!result ||
106108
(options.ignoreEnvironmentVariableSubstitution ?? true)

lib/loader/remote-loader.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ export const remoteLoader = <T = any>(
4646
url: string,
4747
options: RemoteLoaderOptions = {},
4848
): (() => Promise<T>) => {
49-
const HttpService = loadPackage('@nestjs/axios', 'remoteLoader', () =>
50-
require('@nestjs/axios'),
49+
const HttpService = loadPackage<Awaited<typeof import('@nestjs/axios')>>(
50+
'@nestjs/axios',
51+
'remoteLoader',
52+
() => require('@nestjs/axios'),
5153
).HttpService;
52-
const axios = loadPackage('axios', 'remoteLoader', () => require('axios'));
54+
const axios = loadPackage<Awaited<typeof import('axios')['default']>>(
55+
'axios',
56+
'remoteLoader',
57+
() => require('axios'),
58+
);
5359

5460
return async (): Promise<T> => {
5561
const {
@@ -108,23 +114,23 @@ export const remoteLoader = <T = any>(
108114
return parseJson(content);
109115
},
110116
yaml: (content: string) => {
111-
const parseYaml = loadPackage(
117+
const parseYaml = loadPackage<Awaited<typeof import('yaml')>>(
112118
'yaml',
113119
"remoteLoader's ability to parse YAML files",
114120
() => require('yaml'),
115121
).parse;
116122
return parseYaml(content);
117123
},
118124
yml: (content: string) => {
119-
const parseYaml = loadPackage(
125+
const parseYaml = loadPackage<Awaited<typeof import('yaml')>>(
120126
'yaml',
121127
"remoteLoader's ability to parse YML files",
122128
() => require('yaml'),
123129
).parse;
124130
return parseYaml(content);
125131
},
126132
toml: (content: string) => {
127-
const parseToml = loadPackage(
133+
const parseToml = loadPackage<Awaited<typeof import('@iarna/toml')>>(
128134
'@iarna/toml',
129135
"remoteLoader's ability to parse TOML files",
130136
() => require('@iarna/toml'),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"husky": "8.0.3",
8383
"jest": "29.7.0",
8484
"lint-staged": "14.0.1",
85-
"parse-json": "7.1.0",
85+
"parse-json": "8.3.0",
8686
"prettier": "2.8.8",
8787
"reflect-metadata": "0.1.13",
8888
"rimraf": "5.0.1",

0 commit comments

Comments
 (0)