Skip to content

Commit a4bebdb

Browse files
committed
fix(complex-types): support TypeReference with type parameters
1 parent da16fb7 commit a4bebdb

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

packages/complex-types/src/core/printer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ export class Printer {
390390
} else if (ts.isTypeLiteralNode(node)) {
391391
return this.printTypeLiteralNode(node);
392392
} else if (ts.isTypeReferenceNode(node)) {
393-
return this.print(node.typeName);
393+
return node.typeArguments
394+
? this.printTypeByType(node)
395+
: this.print(node.typeName);
394396
} else if (ts.isInterfaceDeclaration(node)) {
395397
return this.printInterfaceDeclaration(node);
396398
} else if (ts.isTypeAliasDeclaration(node)) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import type { ExtractPropTypes } from "vue";
3+
const testProps = {
4+
a: {
5+
type: String,
6+
},
7+
};
8+
9+
type TestProps = ExtractPropTypes<typeof testProps>;
10+
defineProps<TestProps>();
11+
</script>

packages/complex-types/test/__snapshots__/fixtures-compiled.test.ts.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,32 @@ export { core_8468 as default };
491491
"
492492
`;
493493
494+
exports[`fixtures compiled > __fixtures__/defineProps/core#9774.vue 1`] = `
495+
"// core_9774.js
496+
import { defineComponent } from 'vue';
497+
import _export_sfc from '[NULL]/plugin-vue/export-helper';
498+
499+
var _sfc_main = /* @__PURE__ */ defineComponent({
500+
__name: "core#9774",
501+
props: { a: { required: false } },
502+
setup(__props, { expose: __expose }) {
503+
__expose();
504+
const testProps = { a: { type: String } };
505+
const __returned__ = { testProps };
506+
Object.defineProperty(__returned__, "__isScriptSetup", {
507+
enumerable: false,
508+
value: true
509+
});
510+
return __returned__;
511+
}
512+
});
513+
514+
var core_9774 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
515+
516+
export { core_9774 as default };
517+
"
518+
`;
519+
494520
exports[`fixtures compiled > __fixtures__/defineProps/import-from-vue.vue 1`] = `
495521
"// import-from-vue.js
496522
import { defineComponent } from 'vue';

packages/complex-types/test/__snapshots__/fixtures.test.ts.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,23 @@ value: number
232232
"
233233
`;
234234

235+
exports[`fixtures > __fixtures__/defineProps/core#9774.vue 1`] = `
236+
"<script setup lang="ts">
237+
import type { ExtractPropTypes } from "vue";
238+
const testProps = {
239+
a: {
240+
type: String,
241+
},
242+
};
243+
244+
type TestProps = ExtractPropTypes<typeof testProps>;
245+
defineProps<{
246+
a?: string | undefined
247+
}>();
248+
</script>
249+
"
250+
`;
251+
235252
exports[`fixtures > __fixtures__/defineProps/import-from-vue.vue 1`] = `
236253
"<script setup lang="ts" generic="T extends string">
237254
import type { Foo } from "./import-from-vue-vue.exclude.vue";

0 commit comments

Comments
 (0)