51 const authenticated = (await securePersistence.getItem("foo")) === "bar"
52 if (!authenticated) {
53 await sessionPersistence.removeItem("spendingPassword")
54 return unlockWalletForm.setError("spendingPassword", {55 type: "wrongPassword",56 message: "The spending password is wrong",57 })58 }
59 navigate("/dashboard")
60 })
51 })
52 }, 1000)
53 chrome.runtime.onMessage.addListener(listener)
54 const closeListener = (closedWindowId: number) => {55 chrome.windows.onRemoved.removeListener(closeListener)
56 if (closedWindowId === newWindow?.id) {
57 return reject(new Error("4001 - User Rejected Request"))
19 height: 772,
20 state: "normal",
21 })
22 .then(async (newWindow) => {23 const listener = (response: any) => {
24 if (response.windowId === newWindow?.id) {
25 chrome.runtime.onMessage.removeListener(listener)
2
3function runCommand(command: string): Promise<void> {
4 return new Promise((resolve, reject) => {
5 exec(command, (error, stdout, stderr) => { 6 if (error) {
7 console.error(`Error: ${error.message}`)
8 return reject(error)
62 )
63 mixpanel.track("WalletRestored")
64 await setVaultStateInitialized()
65 return navigate("/onboarding/finish")66 } finally {
67 setRestoring(false)
68 }
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}