Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added TS to open-browser file #6574

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/utils/open-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import isDockerContainer from 'is-docker'

import { chalk, log } from './command-helpers.js'

// @ts-expect-error TS(7031) FIXME: Binding element 'message' implicitly has an 'any' ... Remove this comment to see the full error message
const unableToOpenBrowserMessage = function ({ message, url }) {
type BrowserUnableMessage = {
message: string
url: string
}

const unableToOpenBrowserMessage = function ({ message, url }: BrowserUnableMessage) {
log('---------------------------')
log(chalk.redBright(`Error: Unable to open browser automatically: ${message}`))
log(chalk.cyan('Please open your browser and open the URL below:'))
log(chalk.bold(url))
log('---------------------------')
}

/**
* Opens a browser and logs a message if it is not possible
* @param {object} config
* @param {string} config.url The url to open
* @param {boolean} [config.silentBrowserNoneError]
* @returns {Promise<void>}
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'silentBrowserNoneError' implicitl... Remove this comment to see the full error message
const openBrowser = async function ({ silentBrowserNoneError, url }) {
type OpenBrowsrProps = {
silentBrowserNoneError: boolean
url: string
}

const openBrowser = async function ({ silentBrowserNoneError, url }: OpenBrowsrProps) {
if (isDockerContainer()) {
unableToOpenBrowserMessage({ url, message: 'Running inside a docker container' })
return
Expand All @@ -38,8 +39,9 @@ const openBrowser = async function ({ silentBrowserNoneError, url }) {
try {
await open(url)
} catch (error) {
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
unableToOpenBrowserMessage({ url, message: error.message })
if (error instanceof Error) {
unableToOpenBrowserMessage({ url, message: error.message })
}
}
}

Expand Down
Loading