Closed farnabaz closed 1 year ago
Hi there!
I have a use case where components share some props:
First, let's assume we have a component responsible to display images:
<script setup lang="ts">
export type ImageComponentSize = 'small' | 'medium' | 'large'
export interface ImageComponentProps {
src: string
srcDark?: string
size?: ImageComponentSize
}
const props = withDefaults(defineProps<ImageComponentProps>(), {
srcDark: undefined,
size: 'medium',
})
</script>
Then we want to create a simple Gallery that reuse this component (without slots):
<script setup lang="ts">
import type { ImageComponentProps } from './ImageComponent.vue'
export interface GalleryProps {
images: ImageComponentProps[]
}
const props = withDefaults(defineProps<GalleryProps>(), {})
</script>
I was trying to get them by simply parse ASTs (either with compileScript
from vue sfc compiler or createSourceFile
from typescript) but to handle this case we have to resolve the import type
, which can be really memory consuming.
Maybe we can afford this time/memory because we are performing those operations only once at the built time, What do you think?
Agree we don’t mind about the memory since it is only for build time
Extract props info from script setup
defineProps({ ... })
defineProps<{ ... }>()