Skip to content
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

fix(compiler-sfc): add type for props include Function in prod mode #4938

Merged
merged 2 commits into from Nov 15, 2021

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Nov 12, 2021

Solve the problem of the following scenarios:

app.vue:

<script setup>
import Child from './Comp.vue'
</script>

<template>
  <Child />
</template>

Comp.vue:

<script setup lang='ts'>
  
import { onMounted } from 'vue'
  
var props = withDefaults(defineProps<{f?: Function}>(),{f:()=>[1,2,3]})

onMounted(()=>{
  console.log("f:",props.f)
})
  
</script>
  • What is expected?
    Expect the console print results to be consistent in prod mode and dev mode.
    But in dev mode print : f: ()=>[1,2,3]
    in prod mode print : f: [1,2,3]

@@ -692,11 +692,9 @@ export function compileScript(
)}, required: ${required}${
defaultString ? `, ${defaultString}` : ``
} }`
} else if (type.indexOf('Boolean') > -1) {
} else if (type.some(el => el === 'Boolean' || el === 'Function')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimization: when type is Function, prod type is only needed if default is also used.

@yyx990803 yyx990803 merged commit 9c42a1e into vuejs:master Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants