@@ -820,7 +820,7 @@ describe('function syntax w/ expose', () => {
820820describe ( 'function syntax w/ runtime props' , ( ) => {
821821 // with runtime props, the runtime props must match
822822 // manual type declaration
823- defineVaporComponent (
823+ const Comp1 = defineVaporComponent (
824824 ( _props : { msg : string } ) => {
825825 return [ ]
826826 } ,
@@ -829,7 +829,34 @@ describe('function syntax w/ runtime props', () => {
829829 } ,
830830 )
831831
832+ // @ts -expect-error bar isn't specified in props definition
832833 defineVaporComponent (
834+ ( _props : { msg : string } ) => {
835+ return [ ]
836+ } ,
837+ {
838+ props : [ 'msg' , 'bar' ] ,
839+ } ,
840+ )
841+
842+ defineVaporComponent (
843+ ( _props : { msg : string ; bar : string } ) => {
844+ return [ ]
845+ } ,
846+ {
847+ props : [ 'msg' ] ,
848+ } ,
849+ )
850+
851+ expectType < JSX . Element > ( < Comp1 msg = "1" /> )
852+ // @ts -expect-error msg type is incorrect
853+ expectType < JSX . Element > ( < Comp1 msg = { 1 } /> )
854+ // @ts -expect-error msg is missing
855+ expectType < JSX . Element > ( < Comp1 /> )
856+ // @ts -expect-error bar doesn't exist
857+ expectType < JSX . Element > ( < Comp1 msg = "1" bar = "2" /> )
858+
859+ const Comp2 = defineVaporComponent (
833860 < T extends string > ( _props : { msg : T } ) => {
834861 return [ ]
835862 } ,
@@ -838,7 +865,36 @@ describe('function syntax w/ runtime props', () => {
838865 } ,
839866 )
840867
868+ // @ts -expect-error bar isn't specified in props definition
841869 defineVaporComponent (
870+ < T extends string > ( _props : { msg : T } ) => {
871+ return [ ]
872+ } ,
873+ {
874+ props : [ 'msg' , 'bar' ] ,
875+ } ,
876+ )
877+
878+ defineVaporComponent (
879+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
880+ return [ ]
881+ } ,
882+ {
883+ props : [ 'msg' ] ,
884+ } ,
885+ )
886+
887+ expectType < JSX . Element > ( < Comp2 msg = "1" /> )
888+ expectType < JSX . Element > ( < Comp2 < string > msg = "1" /> )
889+ // @ts -expect-error msg type is incorrect
890+ expectType < JSX . Element > ( < Comp2 msg = { 1 } /> )
891+ // @ts -expect-error msg is missing
892+ expectType < JSX . Element > ( < Comp2 /> )
893+ // @ts -expect-error bar doesn't exist
894+ expectType < JSX . Element > ( < Comp2 msg = "1" bar = "2" /> )
895+
896+ // Note: generics aren't supported with object runtime props
897+ const Comp3 = defineVaporComponent (
842898 < T extends string > ( _props : { msg : T } ) => {
843899 return [ ]
844900 } ,
@@ -849,37 +905,58 @@ describe('function syntax w/ runtime props', () => {
849905 } ,
850906 )
851907
852- // @ts -expect-error string prop names don't match
853908 defineVaporComponent (
854- ( _props : { msg : string } ) => {
909+ // @ts -expect-error bar isn't specified in props definition
910+ < T extends string > ( _props : { msg : T } ) => {
855911 return [ ]
856912 } ,
857913 {
858- props : [ 'bar' ] ,
914+ props : {
915+ bar : String ,
916+ } ,
859917 } ,
860918 )
861919
862920 defineVaporComponent (
863- ( _props : { msg : string } ) => {
921+ // @ts -expect-error generics aren't supported with object runtime props
922+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
864923 return [ ]
865924 } ,
866925 {
867926 props : {
868- // @ts -expect-error prop type mismatch
869- msg : Number ,
927+ msg : String ,
870928 } ,
871929 } ,
872930 )
873931
874- // @ts -expect-error prop keys don't match
932+ expectType < JSX . Element > ( < Comp3 msg = "1" /> )
933+ // @ts -expect-error generics aren't supported with object runtime props
934+ expectType < JSX . Element > ( < Comp3 < string > msg = "1" /> )
935+ // @ts -expect-error msg type is incorrect
936+ expectType < JSX . Element > ( < Comp3 msg = { 1 } /> )
937+ // @ts -expect-error msg is missing
938+ expectType < JSX . Element > ( < Comp3 /> )
939+ // @ts -expect-error bar doesn't exist
940+ expectType < JSX . Element > ( < Comp3 msg = "1" bar = "2" /> )
941+
942+ // @ts -expect-error string prop names don't match
875943 defineVaporComponent (
876- ( _props : { msg : string } , ctx ) => {
944+ ( _props : { msg : string } ) => {
945+ return [ ]
946+ } ,
947+ {
948+ props : [ 'bar' ] ,
949+ } ,
950+ )
951+
952+ defineVaporComponent (
953+ ( _props : { msg : string } ) => {
877954 return [ ]
878955 } ,
879956 {
880957 props : {
881- msg : String ,
882- bar : String ,
958+ // @ts -expect-error prop type mismatch
959+ msg : Number ,
883960 } ,
884961 } ,
885962 )
0 commit comments