Skip to content

Commit c661f69

Browse files
committed
fix(git): ambiguous reduce type
1 parent 7828841 commit c661f69

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Diff for: src/git.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const postProcessBranches =
6969
.map((branch) => {
7070
let name = branch.trim();
7171
const parts = branch.match(/\S+/g);
72-
if (parts.length > 1) {
72+
if (parts && parts.length > 1) {
7373
if (parts[0] === "*") {
7474
// We are in a detached HEAD state
7575
if (branch.includes("HEAD detached")) {
@@ -108,6 +108,7 @@ const postProcessBranches =
108108
};
109109
})
110110
.filter((suggestion) => {
111+
if (!suggestion) return false;
111112
if (seen.has(suggestion.name)) return false;
112113
seen.add(suggestion.name);
113114
return true;
@@ -259,7 +260,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
259260
custom: async (tokens, executeShellCommand) => {
260261
const pp = postProcessBranches({ insertWithoutRemotes: true });
261262
if (tokens.includes("-r")) {
262-
return pp(
263+
return pp?.(
263264
(
264265
await executeShellCommand({
265266
command: "git",
@@ -274,7 +275,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
274275
tokens
275276
);
276277
} else {
277-
return pp(
278+
return pp?.(
278279
(
279280
await executeShellCommand({
280281
command: "git",
@@ -295,14 +296,16 @@ export const gitGenerators: Record<string, Fig.Generator> = {
295296
remotes: {
296297
script: ["git", "--no-optional-locks", "remote", "-v"],
297298
postProcess: function (out) {
298-
const remoteURLs = out.split("\n").reduce((dict, line) => {
299-
const pair = line.split("\t");
300-
const remote = pair[0];
301-
const url = pair[1].split(" ")[0];
299+
const remoteURLs = out
300+
.split("\n")
301+
.reduce<Record<string, string>>((dict, line) => {
302+
const pair = line.split("\t");
303+
const remote = pair[0];
304+
const url = pair[1].split(" ")[0];
302305

303-
dict[remote] = url;
304-
return dict;
305-
}, {});
306+
dict[remote] = url;
307+
return dict;
308+
}, {});
306309

307310
return Object.keys(remoteURLs).map((remote) => {
308311
const url = remoteURLs[remote];

0 commit comments

Comments
 (0)