-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Valid typescript when using defineEmits() results in bad code transformation during compile #5393
Comments
Ah, the above doesn't work either, it results in a runtime error, "ReferenceError: defineEmits is not defined" I can leave it untyped as a workaround, but since in my actual implementation the Emits interface is NOT contained in the SFC file, I need a way to type check the usage of the emit function. EDIT: const rawEmit = defineEmits(['foo'])
const emit: Emits = rawEmit |
you should use type declaration const emit = defineEmits<Emits>() |
Ideally, but
|
I hate using GitHub on mobile... Didn't mean to close |
I have this too in version 3.2.31 No interface available. I do not agree that it is a "feature" or a "nice to have" |
@nborko how could you work around the problem with as that still needs the Emits type which does not exist... |
You're looking for this?#5393 (comment) |
As a quick explanation of my setup, I have a subdirectory for each component with the following structure: // types.ts
// heavily documented with tsdoc
interface MyComponentProps {
...
}
// heavily documented with tsdoc
interface MyComponentEmits {
...
}
// synthetic type for api-extractor
// tsdoc style documentation for the actual component
interface MyComponent {
props: MyComponentProps
emits: MyComponentEmits
} <comment><!-- MyComponent.vue --></comment>
<script setup lang="ts">
import { MyComponentEmits, MyComponentProps } from './types'
const props: MyComponentProps = defineProps({
...
})
// This is broken
const emit: MyComponentEmits = defineEmits([ ... ])
// some functionality
</script> // index.ts
export { default as MyComponent } from './MyComponent.vue' This helps keep the documentation and types separated from the SFC to keep the code clean and easier to maintain, and I point api-extractor to a top level types.ts that imports and re-exports the types from each of the components, for further processing into API documentation. EDIT: Updated the sample synthetic interface for clarity |
Version
3.2.30
Reproduction link
sfc.vuejs.org/
Steps to reproduce
In a
<script setup lang="ts">
block, this causes an error during compilation:From vite:
What is expected?
It should compile
What is actually happening?
Doesn't compile
This looks like a transformation error in the vue compiler, since the following works fine as a workaround:
But the above code is valid typescript and shouldn't result in what is being generated.
The text was updated successfully, but these errors were encountered: