Skip to content

Commit

Permalink
fix(api): resolve interface declarations
Browse files Browse the repository at this point in the history
closes #260
  • Loading branch information
sxzz committed Feb 6, 2023
1 parent d32e2c3 commit 66d7c24
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/wild-steaks-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@vue-macros/better-define': patch
'@vue-macros/api': patch
---

resolve interface declarations
3 changes: 3 additions & 0 deletions packages/api/src/vue/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export async function inferRuntimeType(
case 'TSSymbolKeyword':
return ['Symbol']

case 'TSInterfaceDeclaration':
return ['Object']

default:
return [`null`] // no runtime check
}
Expand Down
60 changes: 60 additions & 0 deletions packages/better-define/tests/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,66 @@ export { intersection as default };
"
`;

exports[`fixtures > tests/fixtures/issue-260.vue > isProduction = false 1`] = `
"import { defineComponent, toDisplayString } from 'vue';
var _sfc_main = /* @__PURE__ */ defineComponent({
__name: \\"issue-260\\",
props: {
\\"menu\\": { type: [Object, Array], required: false, default: () => ({ txt: \\"1-1\\" }) }
},
setup(__props) {
const props = __props;
return (_ctx, _cache) => {
return toDisplayString(props.menu);
};
}
});
var _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { issue260 as default };
"
`;

exports[`fixtures > tests/fixtures/issue-260.vue > isProduction = true 1`] = `
"import { defineComponent, toDisplayString } from 'vue';
var _sfc_main = /* @__PURE__ */ defineComponent({
__name: \\"issue-260\\",
props: {
\\"menu\\": { default: () => ({ txt: \\"1-1\\" }) }
},
setup(__props) {
const props = __props;
return (_ctx, _cache) => {
return toDisplayString(props.menu);
};
}
});
var _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { issue260 as default };
"
`;

exports[`fixtures > tests/fixtures/optional-method.vue > isProduction = false 1`] = `
"import { defineComponent } from 'vue';
Expand Down
19 changes: 19 additions & 0 deletions packages/better-define/tests/fixtures/issue-260.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">
export interface IMenu {
txt: string
children?: IMenu[]
}
const props = withDefaults(
defineProps<{
menu?: IMenu | IMenu[]
}>(),
{
menu: () => ({ txt: '1-1' }),
}
)
</script>

<template>
{{ props.menu }}
</template>

0 comments on commit 66d7c24

Please sign in to comment.