@@ -12,15 +12,15 @@ import { track } from '../../utils/telemetry/index.js'
1212import type { SiteInfo } from '../../utils/types.js'
1313import BaseCommand from '../base-command.js'
1414
15- const linkPrompt = async ( command : BaseCommand , options : OptionValues ) => {
15+ const linkPrompt = async ( command : BaseCommand , options : OptionValues ) : Promise < SiteInfo > => {
1616 const { api, state } = command . netlify
1717
1818 const SITE_NAME_PROMPT = 'Search by full or partial site name'
1919 const SITE_LIST_PROMPT = 'Choose from a list of your recently updated sites'
2020 const SITE_ID_PROMPT = 'Enter a site ID'
2121
2222 let GIT_REMOTE_PROMPT = 'Use the current git remote origin URL'
23- let site
23+ let site ! : SiteInfo
2424 // Get git remote data if exists
2525 const repoData = await getRepoData ( { workingDir : command . workingDir , remoteName : options . gitRemoteName } )
2626
@@ -35,16 +35,16 @@ const linkPrompt = async (command: BaseCommand, options: OptionValues) => {
3535 log ( )
3636 log ( `${ chalk . cyanBright ( 'netlify link' ) } will connect this folder to a site on Netlify` )
3737 log ( )
38- const { linkType } = await inquirer . prompt ( [
38+ const { linkType } = ( await inquirer . prompt ( [
3939 {
4040 type : 'list' ,
4141 name : 'linkType' ,
4242 message : 'How do you want to link this folder to a site?' ,
4343 choices : linkChoices ,
4444 } ,
45- ] )
45+ ] ) ) as { linkType : typeof linkChoices [ number ] }
4646
47- let kind
47+ let kind : 'byName' | 'bySiteId' | 'fromList' | 'gitRemote'
4848 switch ( linkType ) {
4949 case GIT_REMOTE_PROMPT : {
5050 // TODO(serhalp): Refactor function to avoid this. We can only be here if `repoData` is not an error.
@@ -88,7 +88,7 @@ Run ${chalk.cyanBright('git remote -v')} to see a list of your git remotes.`)
8888 log ( `Found ${ matchingSites . length } matching sites!` )
8989
9090 // Prompt which options
91- const { selectedSite } = await inquirer . prompt ( [
91+ const { selectedSite } = ( await inquirer . prompt ( [
9292 {
9393 type : 'list' ,
9494 name : 'selectedSite' ,
@@ -98,7 +98,7 @@ Run ${chalk.cyanBright('git remote -v')} to see a list of your git remotes.`)
9898 value : matchingSite ,
9999 } ) ) ,
100100 } ,
101- ] )
101+ ] ) ) as { selectedSite : SiteInfo | undefined }
102102 if ( ! selectedSite ) {
103103 return logAndThrowError ( 'No site selected' )
104104 }
@@ -165,7 +165,7 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
165165 log ( `Fetching recently updated sites...` )
166166 log ( )
167167
168- let sites
168+ let sites : SiteInfo [ ]
169169 try {
170170 sites = await listSites ( { api, options : { maxPages : 1 , filter : 'all' } } )
171171 } catch ( error_ ) {
@@ -204,6 +204,7 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
204204 ] )
205205
206206 try {
207+ // @ts -expect-error(serhalp) -- Mismatch between hardcoded `SiteInfo` and generated Netlify API types.
207208 site = await api . getSite ( { siteId } )
208209 } catch ( error_ ) {
209210 if ( ( error_ as APIError ) . status === 404 ) {
@@ -215,7 +216,9 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
215216 break
216217 }
217218 default :
218- return
219+ // This is not possible, but since the fixed set of choices contains one dynamically interpolated string,
220+ // we can't tell TS that these are exhaustive values
221+ return logAndThrowError ( new Error ( 'Invalid link type selected' ) )
219222 }
220223
221224 if ( ! site ) {
0 commit comments