Skip to content

Commit

Permalink
chore: added TS to open-browser file (#6574)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahThor committed May 10, 2024
1 parent a79430f commit d13cb53
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/utils/open-browser.ts
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

2 comments on commit d13cb53

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,347
  • Package size: 312 MB
  • Number of ts-expect-error directives: 993

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,347
  • Package size: 312 MB
  • Number of ts-expect-error directives: 993

Please sign in to comment.