Skip to content

Commit ea081fe

Browse files
committed
chore: reduce use of any types
1 parent ce32533 commit ea081fe

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

packages/kit/src/exports/vite/dev/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
6868
async function loud_ssr_load_module(url) {
6969
try {
7070
return await vite.ssrLoadModule(url, { fixStacktrace: true });
71-
} catch (/** @type {any} */ err) {
71+
} catch (/** @type {unknown} */ e) {
72+
const err = /** @type {import('rollup').RollupError} */ (e);
7273
const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]);
7374

7475
if (!vite.config.logger.hasErrorLogged(err)) {
@@ -77,13 +78,13 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
7778

7879
vite.ws.send({
7980
type: 'error',
80-
err: {
81+
err: /** @type {import('vite').ErrorPayload['err']} */ ({
8182
...err,
8283
// these properties are non-enumerable and will
8384
// not be serialized unless we explicitly include them
8485
message: err.message,
85-
stack: err.stack
86-
}
86+
stack: err.stack ?? ''
87+
})
8788
});
8889

8990
throw err;
@@ -204,7 +205,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
204205

205206
if (node.universal) {
206207
if (node.page_options?.ssr === false) {
207-
result.universal = node.page_options;
208+
result.universal = /** @type {import('types').UniversalNode} */ (node.page_options);
208209
} else {
209210
// TODO: explain why the file was loaded on the server if we fail to load it
210211
const { module, module_node } = await resolve(node.universal);

packages/kit/src/exports/vite/index.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ async function kit({ svelte_config }) {
424424
];
425425
}
426426

427-
warn_overridden_config(config, new_config);
427+
warn_overridden_config(
428+
/** @type {Record<string, unknown>} */ (config),
429+
/** @type {Record<string, unknown>} */ (new_config)
430+
);
428431

429432
return new_config;
430433
}
@@ -997,7 +1000,10 @@ async function kit({ svelte_config }) {
9971000
};
9981001
}
9991002

1000-
warn_overridden_config(config, new_config);
1003+
warn_overridden_config(
1004+
/** @type {Record<string, unknown>} */ (config),
1005+
/** @type {Record<string, unknown>} */ (new_config)
1006+
);
10011007

10021008
return new_config;
10031009
}
@@ -1148,7 +1154,11 @@ async function kit({ svelte_config }) {
11481154
client_chunks = bundle.output;
11491155
} catch (e) {
11501156
const error =
1151-
e instanceof Error ? e : new Error(/** @type {any} */ (e).message ?? e ?? '<unknown>');
1157+
e instanceof Error
1158+
? e
1159+
: new Error(
1160+
/** @type {{ message?: string }} */ (e).message ?? String(e) ?? '<unknown>'
1161+
);
11521162

11531163
// without this, errors that occur during the secondary build
11541164
// will be logged twice
@@ -1421,8 +1431,8 @@ async function kit({ svelte_config }) {
14211431
}
14221432

14231433
/**
1424-
* @param {Record<string, any>} config
1425-
* @param {Record<string, any>} resolved_config
1434+
* @param {Record<string, unknown>} config
1435+
* @param {Record<string, unknown>} resolved_config
14261436
*/
14271437
function warn_overridden_config(config, resolved_config) {
14281438
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
@@ -1436,8 +1446,8 @@ function warn_overridden_config(config, resolved_config) {
14361446
}
14371447

14381448
/**
1439-
* @param {Record<string, any>} config
1440-
* @param {Record<string, any>} resolved_config
1449+
* @param {Record<string, unknown>} config
1450+
* @param {Record<string, unknown>} resolved_config
14411451
* @param {import('./types.js').EnforcedConfig} enforced_config
14421452
* @param {string} path
14431453
* @param {string[]} out used locally to compute the return value
@@ -1456,7 +1466,13 @@ function find_overridden_config(config, resolved_config, enforced_config, path,
14561466
out.push(path + key);
14571467
}
14581468
} else {
1459-
find_overridden_config(config[key], resolved_config[key], enforced, path + key + '.', out);
1469+
find_overridden_config(
1470+
/** @type {Record<string, unknown>} */ (config[key]),
1471+
/** @type {Record<string, unknown>} */ (resolved_config[key]),
1472+
enforced,
1473+
path + key + '.',
1474+
out
1475+
);
14601476
}
14611477
}
14621478
}

0 commit comments

Comments
 (0)