wheatjs / vite-plugin-vue-type-imports

Import types in Vue SFC for defineProps
223 stars 17 forks source link

Type nesting is not imported #3

Closed sxzz closed 2 years ago

sxzz commented 2 years ago
// types.ts
type A = string
export interface Props {
  val?: string
  a: A
}
<script setup lang="ts">
// Test.vue
import type { Props } from './types'
defineProps<Props>()
</script>

And it transformed to

import { defineComponent as _defineComponent } from "vue";
const _sfc_main = /* @__PURE__ */ _defineComponent({
  props: {
    val: { type: String, required: false },
    a: { type: null, required: true } // ⚠️ type of `a` is null
  },
  setup(__props, { expose }) {
    expose();
    const __returned__ = {};
    Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
    return __returned__;
  }
});
_sfc_main.__hmrId = "07bdddea";
typeof __VUE_HMR_RUNTIME__ !== "undefined" && __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main);
import.meta.hot.accept(({ default: updated, _rerender_only }) => {
  if (_rerender_only) {
    __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render);
  } else {
    __VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated);
  }
});
import _export_sfc from "plugin-vue:export-helper";
export default /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/Users/kevin/Developer/repos/element-plus/play/src/Test.vue"]]);
Screen Shot 2021-12-02 at 08 16 23 Screen Shot 2021-12-02 at 08 16 44
wheatjs commented 2 years ago

Thanks for the report, I'll see if I can get a fix out this weekend

g191091788 commented 2 years ago

Please support namespace! thanks!

export namespace Params {
  export interface User {
    name: string;
    pwd: string;
  }
}
wheatjs commented 2 years ago

@g191091788 I haven't used namespace in the past, can you show me how you would be using it in the vue file so I know how to support it

g191091788 commented 2 years ago

@wheatjs example

wheatjs commented 2 years ago

Thanks!

wheatjs commented 2 years ago

Type nesting should work now, trying installing the latest version

wheatjs commented 2 years ago

@g191091788 It seems like the official Vue library doesn't support namespaces like they do interfaces or types. I'd suggest raising an issue with Vue first. If they decide to support it there, I'll add support for it to this plugin as well

sxzz commented 2 years ago

OK. Thanks!