-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
defineProps() compiler hint fails if wrapped in another function call, i.e. toRefs #5104
Comments
Duplicate #4994, this is the expected behavior, but maybe people need a proper hint from the document. |
So why can't we improve him? Is there any other reason? thanks |
Only stand for my personal view: <script setup>
import { computed, onUpdated, ref, toRefs } from 'vue'
const props = defineProps({
value: Number,
})
const { value } = toRefs(props)
// If we can do this
// const { value } = toRefs(defineProps({
// value: Number,
// }))
// How about this? Please note that, props still can be declared, it's so weird
// if ( a > 1 ) {
// const props = defineProps({
// value: Number,
// })
// }
</script> Macro is magic, we have to be careful while using. We hope props should be declared in the outermost scope, equivalent to defineComponent({
props: {
//....
},
setup () {
//....
}
}) this should not be allowed defineComponent({
setup () {
if ( a > 1 ) {
props: {
//....
},
}
}
}) |
But this is a common way to use it, we want props be reactive |
Yep, I'm with you, meanwhile, we'd better not open Pandora's Box. |
Also with reactivity transform, there is no need to use |
This is my use case: <script setup lang="ts">
import { ref, onMounted, watch, toRefs } from 'vue';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import './userWorker';
type Editor = ReturnType<typeof monaco.editor.create>;
type SupportedLanguage = 'typescript' | 'javascript' | 'json';
interface EditorProps {
source: string;
language: SupportedLanguage;
}
// !: using toRefs(defineProps()) to destructure props
const { source, language } = toRefs(defineProps<EditorProps>());
const editorContainer = ref<HTMLDivElement | null>(null);
const editor = ref<Editor | null>(null);
onMounted(() => {
editor.value = monaco.editor.create(editorContainer.value!, {
value: source.value,
language: language.value,
});
}); |
const { isEdit } = toRefs(
withDefaults(
defineProps<{
isEdit?: boolean;
}>(),
{ isEdit: true }
)
); why withDefaults is not defined const props = withDefaults(
defineProps<{
isEdit?: boolean;
}>(),
{ isEdit: true }
);
const { isEdit } = toRefs(props); |
Version
3.2.26
Reproduction link
sfc.vuejs.org/
Steps to reproduce
review comp.vue
What is expected?
work well
What is actually happening?
defineProps is not defined
The text was updated successfully, but these errors were encountered: