vue-tsc support for js emit #640
-
I'm looking to distribute a component library built with Vue3 / TS in single file components. I'd like for the consuming application to have access to the types when using the components. An example of a library that does this well is Naive UI. It has components written in .tsx files which built into individual .js and .d.ts files with the Attempting to do the above with .vue files by running |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 12 replies
-
Not familiar with this case but maybe you could just generate .d.ts files with vue-tsc, then compile .vue to .js files with Vite? Even with Vue 2 I used to build libs like (vue cli): |
Beta Was this translation helpful? Give feedback.
-
Hello, This morning I was trying to do the same thing than @DarrenTheDev (to distribute a component library built with Vue3 / TS in single file components.) I found your discussion, and I tested the final solution from @DarrenTheDev where we replace also the:
To have at the end, all the *.d.ts files in the dist folder. It worked, but at the end I found another solution, the vite-plugin-dts @DarrenTheDev have you tested it? |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the answer. I see that there is also the support for the script setup, At the moment, I don't use I would love to switch back to |
Beta Was this translation helpful? Give feedback.
-
That seems all not work with I can get the But if I build a lib, then import the component form the lib, the slot props type is The And, their type is different in the |
Beta Was this translation helpful? Give feedback.
-
When I use <script>
export default {
props: {
/** comment */
aProp: String
}
}
</script> output: const Comp: DefineComponent<{any, ...... , {
[x: string]: any;
}> And if remove comment or change this into |
Beta Was this translation helpful? Give feedback.
-
I'm using JSX in a Vue3 project. All the files are javascript // SelectedFilters.jsx
import VueTypes from 'vue-types';
const SelectedFilters = {
name: 'SelectedFilters',
props: {
className: VueTypes.string.def(''),
clearAllLabel: VueTypes.string.def('Clear All'),
showClearAll: VueTypes.bool.def(true),
resetToDefault: VueTypes.bool.def(false),
clearAllBlacklistComponents: VueTypes.array,
resetToValues: VueTypes.object,
},
render() {
// rendering logic using JSX
},
}; |
Beta Was this translation helpful? Give feedback.
Not familiar with this case but maybe you could just generate .d.ts files with vue-tsc, then compile .vue to .js files with Vite?
Even with Vue 2 I used to build libs like (vue cli):
vue-cli-service build --target lib && tsc