1- import type { ASTNode } from './ast' ;
1+ import type { ASTNode , ArgumentNode } from './ast' ;
22
33export function printString ( string : string ) {
44 return JSON . stringify ( string ) ;
@@ -8,8 +8,8 @@ export function printBlockString(string: string) {
88 return '"""\n' + string . replace ( / " " " / g, '\\"""' ) + '\n"""' ;
99}
1010
11- const hasItems = < T > ( array : ReadonlyArray < T > | undefined | null ) : array is ReadonlyArray < T > =>
12- ! ! ( array && array . length ) ;
11+ const hasItems = < T > ( array : unknown ) : array is ReadonlyArray < T > =>
12+ ! ! ( array && ( array as unknown [ ] ) . length ) ;
1313
1414const MAX_LINE_LENGTH = 80 ;
1515
@@ -97,7 +97,7 @@ const nodes: {
9797 } ,
9898 FragmentSpread ( node ) {
9999 let out = '...' + node . name . value ;
100- if ( 'arguments' in node && Array . isArray ( node . arguments ) && hasItems ( node . arguments ) )
100+ if ( 'arguments' in node && hasItems < ArgumentNode > ( node . arguments ) )
101101 out += '(' + node . arguments . map ( nodes . Argument ! ) . join ( ', ' ) + ')' ;
102102 if ( hasItems ( node . directives ) ) out += ' ' + node . directives . map ( nodes . Directive ! ) . join ( ' ' ) ;
103103 return out ;
@@ -110,9 +110,8 @@ const nodes: {
110110 } ,
111111 FragmentDefinition ( node ) {
112112 let out = 'fragment ' + node . name . value ;
113- if ( hasItems ( node . variableDefinitions ) ) {
113+ if ( hasItems ( node . variableDefinitions ) )
114114 out += '(' + node . variableDefinitions . map ( nodes . VariableDefinition ! ) . join ( ', ' ) + ')' ;
115- }
116115 out += ' on ' + node . typeCondition . name . value ;
117116 if ( hasItems ( node . directives ) ) out += ' ' + node . directives . map ( nodes . Directive ! ) . join ( ' ' ) ;
118117 return out + ' ' + print ( node . selectionSet ) ;
0 commit comments