File tree Expand file tree Collapse file tree
packages/babel-plugin-resolve-type Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -163,13 +163,21 @@ const plugin: (
163163 if ( generics ) {
164164 ctx ! . propsTypeDecl = resolveTypeReference ( generics )
165165 } else {
166- ctx ! . propsTypeDecl = getTypeAnnotation ( props . left )
166+ const typeAnnotation = getTypeAnnotation ( props . left )
167+ ctx ! . propsTypeDecl =
168+ typeAnnotation && t . isTSTypeReference ( typeAnnotation )
169+ ? resolveTypeReference ( typeAnnotation ) || typeAnnotation
170+ : typeAnnotation
167171 }
168172 ctx ! . propsRuntimeDefaults = props . right
169173 } else if ( generics ) {
170174 ctx ! . propsTypeDecl = resolveTypeReference ( generics )
171175 } else {
172- ctx ! . propsTypeDecl = getTypeAnnotation ( props )
176+ const typeAnnotation = getTypeAnnotation ( props )
177+ ctx ! . propsTypeDecl =
178+ typeAnnotation && t . isTSTypeReference ( typeAnnotation )
179+ ? resolveTypeReference ( typeAnnotation ) || typeAnnotation
180+ : typeAnnotation
173181 }
174182
175183 if ( ! ctx ! . propsTypeDecl ) return
Original file line number Diff line number Diff line change @@ -211,6 +211,26 @@ defineComponent<Props>((props = {
211211} );"
212212`;
213213
214+ exports[`resolve type > runtime props > with type reference annotation 1`] = `
215+ "import { defineComponent } from 'vue';
216+ interface MyProps {
217+ list ?: Array < {
218+ id: number ;
219+ title : string ;
220+ }> ;
221+ }
222+ defineComponent((props: MyProps) => {
223+ return () => <div >{ props .list ? .length }< / div > ;
224+ }, {
225+ props: {
226+ list: {
227+ type: Array ,
228+ required: false
229+ }
230+ }
231+ });"
232+ `;
233+
214234exports [` resolve type > w/ tsx 1` ] = `
215235"import { type SetupContext , defineComponent } from 'vue';
216236defineComponent(() => {
Original file line number Diff line number Diff line change @@ -88,6 +88,24 @@ describe('resolve type', () => {
8888 )
8989 expect ( result ) . toMatchSnapshot ( )
9090 } )
91+
92+ test ( 'with type reference annotation' , async ( ) => {
93+ const result = await transform (
94+ `
95+ import { defineComponent } from 'vue';
96+ interface MyProps {
97+ list?: Array<{
98+ id: number
99+ title: string
100+ }>
101+ }
102+ defineComponent((props: MyProps) => {
103+ return () => <div>{props.list?.length}</div>;
104+ })
105+ ` ,
106+ )
107+ expect ( result ) . toMatchSnapshot ( )
108+ } )
91109 } )
92110
93111 describe ( 'runtime emits' , ( ) => {
You can’t perform that action at this time.
0 commit comments