@@ -193,6 +193,12 @@ test("optional variables are optional", () => {
193193 } ,
194194 } ) ;
195195
196+ let validVariables ! : { limit : number } ;
197+ let excessVariables ! : { limit : number ; foo : string } ;
198+ useQuery ( query , { variables : validVariables } ) ;
199+ // @ts -expect-error unknown variables
200+ useQuery ( query , { variables : excessVariables } ) ;
201+
196202 let skip ! : boolean ;
197203 useQuery ( query , skip ? skipToken : undefined ) ;
198204 useQuery ( query , skip ? skipToken : { } ) ;
@@ -367,6 +373,82 @@ test("requires variables with mixed TVariables", () => {
367373 ) ;
368374} ) ;
369375
376+ test ( "rejects unknown options" , ( ) => {
377+ const literalVariables : TypedDocumentNode <
378+ { character : string } ,
379+ { type : "main" }
380+ > = gql `` ;
381+ const widenedVariables : TypedDocumentNode <
382+ { character : string } ,
383+ { type : string }
384+ > = gql `` ;
385+ const noVariables : TypedDocumentNode <
386+ { greeting : string } ,
387+ Record < string , never >
388+ > = gql `` ;
389+
390+ useQuery ( literalVariables , {
391+ variables : { type : "main" } ,
392+ returnPartialData : true ,
393+ notifyOnNetworkStatusChange : true ,
394+ errorPolicy : "all" ,
395+ context : { foo : 1 } ,
396+ skipPollAttempt : ( ) => false ,
397+ } ) ;
398+
399+ // @ts -expect-error unknown option
400+ useQuery ( literalVariables , {
401+ variables : { type : "main" } ,
402+ returnPartialDta : false ,
403+ } ) ;
404+
405+ // @ts -expect-error unknown option
406+ useQuery ( widenedVariables , {
407+ variables : { type : "main" } ,
408+ returnPartialDta : false ,
409+ } ) ;
410+
411+ // @ts -expect-error unknown option
412+ useQuery ( noVariables , {
413+ returnPartialDta : false ,
414+ } ) ;
415+
416+ // @ts -expect-error unknown option
417+ useQuery ( literalVariables , {
418+ variables : { type : "main" } ,
419+ returnPartialData : true ,
420+ bogusOption : 1 ,
421+ } ) ;
422+
423+ let skip ! : boolean ;
424+ useQuery (
425+ noVariables ,
426+ // @ts -expect-error unknown option
427+ skip ? skipToken : { returnPartialDta : false }
428+ ) ;
429+ useQuery (
430+ literalVariables ,
431+ // @ts -expect-error unknown option
432+ skip ? skipToken : { variables : { type : "main" } , returnPartialDta : false }
433+ ) ;
434+ } ) ;
435+
436+ test ( "rejects a known option with an invalid value" , ( ) => {
437+ const query : TypedDocumentNode < { character : string } , { id : string } > = gql `` ;
438+
439+ useQuery ( query , { variables : { id : "1" } , fetchPolicy : "cache-first" } ) ;
440+ // @ts -expect-error invalid fetchPolicy
441+ useQuery ( query , {
442+ variables : { id : "1" } ,
443+ fetchPolicy : "bogus" ,
444+ } ) ;
445+ // @ts -expect-error invalid errorPolicy
446+ useQuery ( query , {
447+ variables : { id : "1" } ,
448+ errorPolicy : "bogus" ,
449+ } ) ;
450+ } ) ;
451+
370452test ( "constant variable types do not widen returnPartialData" , ( ) => {
371453 {
372454 const query : TypedDocumentNode < { character : string } , { type : "main" } > =
0 commit comments