@@ -12,15 +12,15 @@ import { track } from '../../utils/telemetry/index.js'
12
12
import type { SiteInfo } from '../../utils/types.js'
13
13
import BaseCommand from '../base-command.js'
14
14
15
- const linkPrompt = async ( command : BaseCommand , options : OptionValues ) => {
15
+ const linkPrompt = async ( command : BaseCommand , options : OptionValues ) : Promise < SiteInfo > => {
16
16
const { api, state } = command . netlify
17
17
18
18
const SITE_NAME_PROMPT = 'Search by full or partial site name'
19
19
const SITE_LIST_PROMPT = 'Choose from a list of your recently updated sites'
20
20
const SITE_ID_PROMPT = 'Enter a site ID'
21
21
22
22
let GIT_REMOTE_PROMPT = 'Use the current git remote origin URL'
23
- let site
23
+ let site ! : SiteInfo
24
24
// Get git remote data if exists
25
25
const repoData = await getRepoData ( { workingDir : command . workingDir , remoteName : options . gitRemoteName } )
26
26
@@ -35,16 +35,16 @@ const linkPrompt = async (command: BaseCommand, options: OptionValues) => {
35
35
log ( )
36
36
log ( `${ chalk . cyanBright ( 'netlify link' ) } will connect this folder to a site on Netlify` )
37
37
log ( )
38
- const { linkType } = await inquirer . prompt ( [
38
+ const { linkType } = ( await inquirer . prompt ( [
39
39
{
40
40
type : 'list' ,
41
41
name : 'linkType' ,
42
42
message : 'How do you want to link this folder to a site?' ,
43
43
choices : linkChoices ,
44
44
} ,
45
- ] )
45
+ ] ) ) as { linkType : typeof linkChoices [ number ] }
46
46
47
- let kind
47
+ let kind : 'byName' | 'bySiteId' | 'fromList' | 'gitRemote'
48
48
switch ( linkType ) {
49
49
case GIT_REMOTE_PROMPT : {
50
50
// 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.`)
88
88
log ( `Found ${ matchingSites . length } matching sites!` )
89
89
90
90
// Prompt which options
91
- const { selectedSite } = await inquirer . prompt ( [
91
+ const { selectedSite } = ( await inquirer . prompt ( [
92
92
{
93
93
type : 'list' ,
94
94
name : 'selectedSite' ,
@@ -98,7 +98,7 @@ Run ${chalk.cyanBright('git remote -v')} to see a list of your git remotes.`)
98
98
value : matchingSite ,
99
99
} ) ) ,
100
100
} ,
101
- ] )
101
+ ] ) ) as { selectedSite : SiteInfo | undefined }
102
102
if ( ! selectedSite ) {
103
103
return logAndThrowError ( 'No site selected' )
104
104
}
@@ -165,7 +165,7 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
165
165
log ( `Fetching recently updated sites...` )
166
166
log ( )
167
167
168
- let sites
168
+ let sites : SiteInfo [ ]
169
169
try {
170
170
sites = await listSites ( { api, options : { maxPages : 1 , filter : 'all' } } )
171
171
} catch ( error_ ) {
@@ -204,6 +204,7 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
204
204
] )
205
205
206
206
try {
207
+ // @ts -expect-error(serhalp) -- Mismatch between hardcoded `SiteInfo` and generated Netlify API types.
207
208
site = await api . getSite ( { siteId } )
208
209
} catch ( error_ ) {
209
210
if ( ( error_ as APIError ) . status === 404 ) {
@@ -215,7 +216,9 @@ or run ${chalk.cyanBright('netlify sites:create')} to create a site.`)
215
216
break
216
217
}
217
218
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' ) )
219
222
}
220
223
221
224
if ( ! site ) {
0 commit comments