@@ -186,6 +186,12 @@ export async function queryPRInfo(prNumber: number) {
186186 }
187187}
188188
189+ interface Refs {
190+ readonly head : string ;
191+ readonly master : "master" ;
192+ readonly latestSuggestions : string ;
193+ }
194+
189195// The GQL response => Useful data for us
190196export async function deriveStateForPR (
191197 prInfo : PR_repository_pullRequest ,
@@ -217,7 +223,7 @@ export async function deriveStateForPR(
217223 master : "master" ,
218224 latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
219225 Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
220- } ;
226+ } as const ;
221227 const pkgInfoEtc = await getPackageInfosEtc (
222228 noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
223229 refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -296,11 +302,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
296302}
297303
298304async function getPackageInfosEtc (
299- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
305+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
300306) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
301307 const infos = new Map < string | null , FileInfo [ ] > ( ) ;
302308 for ( const path of paths ) {
303- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
309+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
304310 if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
305311 infos . get ( pkg ) ! . push ( fileInfo ) ;
306312 }
@@ -335,7 +341,9 @@ async function getPackageInfosEtc(
335341 return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
336342}
337343
338- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
344+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
345+
346+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
339347 // https://regex101.com/r/eFvtrz/1
340348 const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
341349 if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -353,8 +361,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
353361}
354362
355363interface ConfigSuspicious {
356- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
357- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
364+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
365+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
358366}
359367const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
360368 const basename = path . replace ( / .* \/ / , "" ) ;
@@ -413,7 +421,7 @@ configSuspicious["tsconfig.json"] = makeChecker(
413421// to it, ignoring some keys. The ignored properties are in most cases checked
414422// elsewhere (dtslint), and in some cases they are irrelevant.
415423function makeChecker ( expectedForm : any , expectedFormUrl : string , options ?: { parse : ( text : string ) => unknown } | { ignore : ( data : any ) => void } ) {
416- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
424+ return async ( newText : string , getContents : GetContents ) => {
417425 let suggestion : any ;
418426 if ( options && "parse" in options ) {
419427 suggestion = options . parse ( newText ) ;
@@ -438,7 +446,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
438446 } ;
439447
440448 // Apply any preexisting diffs to towardsIt
441- async function ignoreExistingDiffs ( ref : string ) {
449+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
442450 const theExpectedForm = `[the expected form](${ expectedFormUrl } )` ;
443451 const diffFromExpected = ( data : any ) => jsonDiff . compare ( towardsIt , data ) ;
444452 const newDiff = diffFromExpected ( newData ) ;
0 commit comments