Skip to content

Commit b7f4cac

Browse files
Fix TypeScript type errors in source files (#20)
TypeScript strict type checking was enabled but the codebase had 7 type errors preventing successful compilation. **Fixed type errors:** - **decompress.js**: Added explicit `Buffer[]` type annotation for chunks array to resolve implicit `any[]` inference - **ffmpeg.js, node.js**: Added missing return statements to match JSDoc `Promise<string>` declarations - **main.js**: Added null check for `semver.coerce()` result and eliminated redundant coerce call - **request.js**: Added undefined check for `res.statusCode` before comparison **Example fix (main.js):** ```javascript // Before: called coerce twice, missing null check } else if (semver.valid(semver.coerce(options.version))) { options.version = semver.coerce(options.version).version; // After: single call with proper null handling } else { const coerced = semver.coerce(options.version); if (coerced && semver.valid(coerced)) { options.version = coerced.version; ``` All changes maintain existing runtime behavior while satisfying TypeScript's strict type checking requirements. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ayushmanchhabra <14110965+ayushmanchhabra@users.noreply.github.com>
1 parent ab6b164 commit b7f4cac

5 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/decompress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async function unzip(zippedFile, cacheDir) {
8787
for (const symlinkEntry of symlinks) {
8888
let entryPathAbs = path.join(cacheDir, symlinkEntry.filename);
8989
const readStream = await symlinkEntry.openReadStream();
90+
/** @type {Buffer[]} */
9091
const chunks = [];
9192
readStream.on('data', (chunk) => chunks.push(chunk));
9293
await new Promise(resolve => readStream.on('end', resolve));

src/ffmpeg.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ export default async function ffmpeg(downloadUrl, version, platform, arch, cache
3535
);
3636

3737
await request(url, ffmpegFileAbs);
38+
return ffmpegFileAbs;
3839
}

src/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ async function get(options) {
5454
|| options.version === "lts"
5555
) {
5656
options.version = manifestData[options.version].slice(1);
57-
} else if (semver.valid(semver.coerce(options.version))) {
58-
options.version = semver.coerce(options.version).version;
5957
} else {
60-
throw new Error('Expected "options.version" to be "latest", "stable", "lts" or a valid semver version. Received: ' + options.version);
58+
const coerced = semver.coerce(options.version);
59+
if (coerced && semver.valid(coerced)) {
60+
options.version = coerced.version;
61+
} else {
62+
throw new Error('Expected "options.version" to be "latest", "stable", "lts" or a valid semver version. Received: ' + options.version);
63+
}
6164
}
6265

6366
if (options.flavor !== "normal" && options.flavor !== "sdk") {

src/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ export default async function nw(downloadUrl, version, cacheDir) {
4545
);
4646

4747
await request(url, nwFileAbs);
48+
return nwFileAbs;
4849
}

src/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function request(url, filePath) {
4444
},
4545
(res) => {
4646
/* Redirect handling */
47-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
47+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
4848
cleanup();
4949

5050
const redirectedUrl = new URL(res.headers.location, parsedUrl).toString();

0 commit comments

Comments
 (0)