@@ -21,6 +21,14 @@ interface PageScriptOnlyProtocol {
2121 panel : Record < string , never >
2222}
2323
24+ interface MixedPanelProtocol {
25+ pageScript : Record < string , never >
26+ panel : {
27+ confirm : ( message : string ) => boolean
28+ notify : ( message : string ) => void
29+ }
30+ }
31+
2432describe ( 'Channel function definitions' , ( ) => {
2533 it ( 'distinguishes event, query, and action definitions' , ( ) => {
2634 defineChannelFunction ( { name : 'notify' , type : 'event' } )
@@ -177,16 +185,18 @@ describe('In-page script channel', () => {
177185 } )
178186
179187 describe ( 'Event checking' , ( ) => {
180- it ( 'types runtime subscriptions to page-script functions ' , ( ) => {
181- const unsubscribe = channel . on ( 'echo ' , ( value ) => {
188+ it ( 'types runtime subscriptions to page-script events ' , ( ) => {
189+ const unsubscribe = channel . on ( 'save ' , ( value ) => {
182190 expectTypeOf ( value ) . toEqualTypeOf < string > ( )
183191 } )
184192
185193 expectTypeOf ( unsubscribe ) . toEqualTypeOf < ( ) => void > ( )
186194 // @ts -expect-error Panel functions cannot be handled by the page script.
187195 channel . on ( 'notify' , ( ) => { } )
188- // @ts -expect-error `echo` listeners receive a string.
189- channel . on ( 'echo' , ( value : number ) => void value )
196+ // @ts -expect-error Query functions cannot be handled as events.
197+ channel . on ( 'echo' , ( ) => { } )
198+ // @ts -expect-error `save` listeners receive a string.
199+ channel . on ( 'save' , ( value : number ) => void value )
190200 } )
191201
192202 it ( 'types panel connection events' , ( ) => {
@@ -353,6 +363,20 @@ describe('Panel channel', () => {
353363 channel . on ( 'notify' , ( message : number ) => void message )
354364 } )
355365
366+ it ( 'rejects runtime subscriptions to panel queries' , ( ) => {
367+ const mixedChannel = connectPanelChannel < MixedPanelProtocol > ( {
368+ name : 'devframes:mixed-panel' ,
369+ functions : {
370+ confirm : { handler : ( ) => true } ,
371+ notify : { type : 'event' } ,
372+ } ,
373+ } )
374+
375+ mixedChannel . on ( 'notify' , ( ) => { } )
376+ // @ts -expect-error Query functions cannot be handled as events.
377+ mixedChannel . on ( 'confirm' , ( ) => { } )
378+ } )
379+
356380 it ( 'types status events' , ( ) => {
357381 const unsubscribe = channel . events . on ( 'status:updated' , ( status ) => {
358382 expectTypeOf ( status ) . toEqualTypeOf < 'connecting' | 'connected' | 'closed' > ( )
0 commit comments