從setup輸出的類型聲明如何能在.ts檔中引用呢? #6009
Unanswered
hkk2018
asked this question in
Help/Questions
Replies: 1 comment 3 replies
-
結果我發現了一個workaroud,就是把類型聲明放在<script lang="ts"></script>裡面,而非放在setup,這樣ts就會正確解析到了,哈哈! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
在Vue3 setup區塊聲明的類型,可以正確地被其他.vue檔解析,但是引用到.ts檔時就會出現以下錯誤:
TS2614: Module '"*.vue"' has no exported member 'ModalConfig'. Did you mean to use 'import ModalConfig from "*.vue"' instead?
我覺得應該是跟shims-vue.d.ts中的配置有關,所以我試著把輸出的類型(ModalConfig)也聲明進去時,ts就不會報錯了,如下:
但這肯定不是解決辦法的,不知道是否有人知道如何正確處置呢?
PS:
之所以要這麼作,是因為該類型聲明是專屬於該.vue檔的內容,所以我希望能集中在一個檔才最好管理、最清楚。
退而求其次的作法是將類型聲明從.vue檔提出,另外創一個ts檔放,但是這樣需要多維護該ts檔跟對應的.vue檔的關聯,比如說要規範相同命名,或者是規範須放置在同個資料夾下等等,我都覺得差強人意。
Beta Was this translation helpful? Give feedback.
All reactions