Skip to content

Commit

Permalink
Adjust types for typescript 4.4
Browse files Browse the repository at this point in the history
Some JSX types (eg. `value?: string`) will probably change to `value?: string | undefined`, so no need to fix those now.
  • Loading branch information
weedz committed Jun 17, 2021
1 parent d78e2eb commit a59ea16
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 52 deletions.
8 changes: 5 additions & 3 deletions src/Components/Branches/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ export function toggleTreeItem(e: h.JSX.TargetedMouseEvent<HTMLAnchorElement>) {
}

function selectAction(c: Link<string>) {
updateStore({selectedBranch: {branch: c.props.linkData}})
if (c.props.linkData) {
updateStore({selectedBranch: {branch: c.props.linkData}});
}
}

// eslint-disable-next-line react/prefer-stateless-function
export class RenderBranchTree extends PureComponent<{
branches: BranchTree
contextMenu?: (event: h.JSX.TargetedMouseEvent<HTMLAnchorElement>) => void
dblClick?: (event: h.JSX.TargetedMouseEvent<HTMLAnchorElement>) => void
contextMenu?: ((event: h.JSX.TargetedMouseEvent<HTMLAnchorElement>) => void) | undefined
dblClick?: ((event: h.JSX.TargetedMouseEvent<HTMLAnchorElement>) => void) | undefined
indent: number
}> {
render() {
Expand Down
14 changes: 10 additions & 4 deletions src/Components/Changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import { IpcAction, IpcActionReturn } from "src/Data/Actions";
import { updateStore, Store, PureStoreComponent } from "../Data/Renderer/store";
import Link from "./Link";

export default class Changes extends PureStoreComponent<unknown, {staged: number, unstaged: number, repoPath: string}> {
state = {
interface State {
staged: number
unstaged: number
}

export default class Changes extends PureStoreComponent<unknown, State> {
state: Readonly<State> = {
staged: 0,
unstaged: 0,
repoPath: "",
};
componentDidMount() {
this.listen("repo", (repo) => {
this.setState({repoPath: repo?.path});
if (repo?.path !== Store.repo?.path) {
this.forceUpdate();
}
});
this.registerHandler(IpcAction.REFRESH_WORKDIR, (changes: IpcActionReturn[IpcAction.REFRESH_WORKDIR]) => {
this.setState({
Expand Down
4 changes: 3 additions & 1 deletion src/Components/CommitList/CommitListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type Props = {
};

function selectCommit(c: Link<string>) {
updateStore({diffPaneSrc: c.props.linkData});
if (c.props.linkData) {
updateStore({diffPaneSrc: c.props.linkData});
}
}

// prefer-stateless-function is disabled for PureComponents from react but is not recognized from preact.
Expand Down
9 changes: 5 additions & 4 deletions src/Components/CommitList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ export default class CommitList extends PureStoreComponent<unknown, State> {
};
}

ipcSendMessage(IpcAction.LOAD_COMMITS, {
cursor: this.cursor,
...options
});
if (this.cursor) {
options.cursor = this.cursor;
}

ipcSendMessage(IpcAction.LOAD_COMMITS, options);
}
handleCommits(fetched: IpcActionReturn[IpcAction.LOAD_COMMITS]) {
if (fetched.branch === "history") {
Expand Down
1 change: 1 addition & 0 deletions src/Components/Dialog/AddRemote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function AddRemote(dialog: DialogProps[DialogTypes.ADD_REMOTE]) {
const data: RemoteProps["data"] = {
name: "",
pullFrom: "",
pushTo: null,
};
return <div className="dialog-window">
<form onSubmit={e => {
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Dialog/CreateTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { CreateTagProps } from "./types";


export function CreateTag(dialog: CreateTagProps) {
const data: {name: string, annotation?: string} = {
name: ""
const data: {name: string, annotation: string} = {
name: "",
annotation: "",
};
return <div className="dialog-window">
<form onSubmit={e => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Dialog/EditRemote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function EditRemote(dialog: RemoteProps) {
</label>
<label>
<p>Push to:</p>
<input type="text" name="push" onChange={e => data.pushTo = e.currentTarget.value} value={data.pushTo} />
<input type="text" name="push" onChange={e => data.pushTo = e.currentTarget.value} value={data.pushTo || ""} />
</label>
<br />
<button type="submit">Confirm</button>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export type CompareProps = {
export type RemoteProps = {
data: {
pullFrom: string
pushTo?: string
pushTo: string | null
name: string
}
confirmCb: (data: RemoteProps["data"]) => void
cancelCb: () => void
};

export type BranchProps = {
defaultValue?: string
defaultValue: string | undefined
confirmCb: (branchName: string) => void
cancelCb: () => void
};
Expand Down
18 changes: 9 additions & 9 deletions src/Data/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type IpcActionParams = {
[IpcAction.LOAD_COMMIT]: string | null
[IpcAction.LOAD_PATCHES_WITHOUT_HUNKS]: {
sha: string
options?: DiffOptions
options: DiffOptions | undefined
}
[IpcAction.LOAD_HUNKS]: (
{
Expand All @@ -84,7 +84,7 @@ export type IpcActionParams = {
[IpcAction.UNSTAGE_FILE]: string
[IpcAction.DISCARD_FILE]: string
[IpcAction.COMMIT]: {
amend?: boolean
amend: boolean | undefined
message: {
summary: string
body: string
Expand Down Expand Up @@ -124,8 +124,8 @@ export type IpcActionParams = {
[IpcAction.OPEN_COMPARE_REVISIONS]: {from: string, to: string}
[IpcAction.REMOTES]: null
[IpcAction.RESOLVE_CONFLICT]: {path: string}
[IpcAction.EDIT_REMOTE]: {oldName: string, name: string, pullFrom: string, pushTo?: string}
[IpcAction.NEW_REMOTE]: {name: string, pullFrom: string, pushTo?: string}
[IpcAction.EDIT_REMOTE]: {oldName: string, name: string, pullFrom: string, pushTo: string | null}
[IpcAction.NEW_REMOTE]: {name: string, pullFrom: string, pushTo: string | null}
[IpcAction.REMOVE_REMOTE]: {name: string}
[IpcAction.FETCH]: null | {remote: string}
[IpcAction.SAVE_SETTINGS]: AppConfig
Expand All @@ -143,7 +143,7 @@ export type IpcActionParams = {
}
[IpcAction.DELETE_TAG]: {
name: string
remote?: boolean
remote: boolean | undefined
}
};

Expand Down Expand Up @@ -190,7 +190,7 @@ export type IpcActionReturn = {
[IpcAction.OPEN_COMPARE_REVISIONS]: PatchObj[]
[IpcAction.REMOTES]: {
name: string
pushTo?: string
pushTo: string | null
pullFrom: string
}[]
[IpcAction.RESOLVE_CONFLICT]: boolean
Expand Down Expand Up @@ -296,7 +296,7 @@ export type BranchObj = {
ahead: number
behind: number
}
remote?: string
remote?: string | undefined
type: RefType
};

Expand All @@ -313,7 +313,7 @@ interface LoadCommitsParamBranch {
}
type LoadFileCommitsParam = {
/** SHA of last fetched commit */
cursor?: string
cursor: string | undefined
startAtCursor?: boolean
num?: number
file: string
Expand All @@ -337,7 +337,7 @@ export type LoadCommitReturn = {
type LoadCommitsReturn = {
commits: LoadCommitReturn[]
branch: string
cursor?: string
cursor?: string | undefined
};
type LoadFileCommitsReturn = {
commits: Array<LoadCommitReturn & {
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type AppConfig = {
sshPublicKey?: string
sshPassphrase?: string
sshAgent: boolean
gpg?: GpgConfig
gpg?: GpgConfig | undefined
}>
selectedProfile: number
};
Expand Down
36 changes: 24 additions & 12 deletions src/Data/Main/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ export async function pull(repo: Repository, branch: string | null, signature: S
try {
ref = await repo.getReference(branch);
} catch (err) {
// invalid ref
dialog.showErrorBox("Pull failed", `Invalid reference '${branch}'\n${err.message}`);
if (err instanceof Error) {
// invalid ref
dialog.showErrorBox("Pull failed", `Invalid reference '${branch}'\n${err.message}`);
}
return false;
}
} else {
Expand Down Expand Up @@ -234,7 +236,9 @@ async function pushHead(repo: Repository, auth: AuthConfig) {
upstream = await Branch.upstream(head);
}
catch (err) {
dialog.showErrorBox("Missing upstream", err.message);
if (err instanceof Error) {
dialog.showErrorBox("Missing upstream", err.message);
}
return false;
}

Expand Down Expand Up @@ -271,7 +275,9 @@ async function pushBranch(repo: Repository, remote: Remote, localRef: Reference,

status = await Graph.aheadBehind(repo, localRef.target(), upstream.target()) as unknown as { ahead: number, behind: number };
} catch (err) {
dialog.showErrorBox("Push failed", `Invalid upstream: ${err.message}`);
if (err instanceof Error) {
dialog.showErrorBox("Push failed", `Invalid upstream: ${err.message}`);
}
return false;
}

Expand Down Expand Up @@ -318,8 +324,10 @@ async function doPush(remote: Remote, localName: string, remoteName: string, aut
return !pushResult;
} catch (err) {
// invalid authentication?
// FIXME: return error message instead of displaying error dialog here
dialog.showErrorBox("Push failed", err.message);
if (err instanceof Error) {
// FIXME: return error message instead of displaying error dialog here
dialog.showErrorBox("Push failed", err.message);
}
}
return false;
}
Expand Down Expand Up @@ -356,7 +364,9 @@ export async function deleteRemoteRef(repo: Repository, refName: string, auth: A
}
});
} catch (err) {
dialog.showErrorBox("No remote ref found", err.message);
if (err instanceof Error) {
dialog.showErrorBox("No remote ref found", err.message);
}
}
ref.delete();
}
Expand Down Expand Up @@ -512,7 +522,7 @@ export async function commit(repo: Repository, params: IpcActionParams[IpcAction
await repo.createCommit("HEAD", committer, committer, message, oid, [parent]);
}
} catch (err) {
return err;
return err as Error;
}

return loadCommit(repo, null);
Expand All @@ -537,7 +547,9 @@ export async function createTag(repo: Repository, data: IpcActionParams[IpcActio
await repo.createLightweightTag(id, data.name);
}
} catch (err) {
dialog.showErrorBox("Failed to create tag", err.toString());
if (err instanceof Error) {
dialog.showErrorBox("Failed to create tag", err.toString());
}
}

return true;
Expand Down Expand Up @@ -1018,7 +1030,7 @@ export async function commitWithDiff(repo: Repository, sha: string) {
return commit;
}

export async function checkoutBranch(repo: Repository, branch: string): Promise<IpcActionReturn[IpcAction.CHECKOUT_BRANCH]> {
export async function checkoutBranch(repo: Repository, branch: string) {
try {
await repo.checkoutBranch(branch);
const head = await repo.head();
Expand All @@ -1029,9 +1041,9 @@ export async function checkoutBranch(repo: Repository, branch: string): Promise<
commit: getCommitObj(headCommit),
normalizedName: head.name(),
type: RefType.LOCAL
};
} as IpcActionReturn[IpcAction.CHECKOUT_BRANCH];
} catch (err) {
return err;
return err as Error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Data/Renderer/Dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { normalizeLocalName, normalizeRemoteNameWithoutRemote, normalizeTagName,
import { ipcGetData, ipcSendMessage } from "./IPC";
import { closeDialogWindow, createBranchFromSha, createBranchFromRef, openDialogWindow, setUpstream, renameLocalBranch } from "./store";

export function openDialog_EditRemote(data: {name: string, pullFrom: string, pushTo?: string}) {
export function openDialog_EditRemote(data: {name: string, pullFrom: string, pushTo: string | null}) {
const oldName = data.name;
openDialogWindow(DialogTypes.EDIT_REMOTE, {
data,
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Renderer/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export type StoreType = {
status: null | RepoStatus
}
branches: BranchesObj
head?: HeadBranchObj
head: HeadBranchObj | undefined
remotes: IpcActionReturn[IpcAction.REMOTES]
heads: {
[key: string]: BranchObj[]
}
currentFile: null | {
commitSHA?: string
commitSHA?: string | undefined
patch: PatchObj
}
locks: {
Expand Down
4 changes: 2 additions & 2 deletions src/Views/WorkingArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export default class WorkingArea extends StoreComponent<unknown, State> {
};
if (!amend) {
newState.commitMsg = Store.commitMsg;
} else {
newState.commitMsg = Store.head?.commit.message
} else if (Store.head) {
newState.commitMsg = Store.head.commit.message;
}
this.setState(newState);
}
Expand Down
Loading

0 comments on commit a59ea16

Please sign in to comment.