computed property inside reactive typescript error #7791
Answered
by
Mayvis
Mayvis
asked this question in
Help/Questions
-
Why using computed property inside reactive method will cause typescript issue? // person will be an any type
const person = reactive({
name: 'Kevin',
age: 12,
tel: '0912345678',
concatData: computed(() => {
return `name: ${person.name}, age:${person.age}, phone: ${person.tel}`
})
}) or I just have to write like below const person = reactive({
name: 'Kevin',
age: 12,
tel: '0912345678',
})
const personConcatData = computed(() => {
return `name: ${person.name}, age:${person.age}, phone: ${person.tel}`
}) |
Beta Was this translation helpful? Give feedback.
Answered by
Mayvis
Feb 25, 2023
Replies: 1 comment
-
Ok, so computed property will cause an type assert loop error. So I have to write another type to handle this situation. // can also use interface
type Person = {
name: string
age: number
tel: string
concatData: string
}
const person: Person = reactive({
name: 'Kevin',
age: 12,
tel: '0912345678',
concatData: computed(() => {
return `name: ${person.name}, age:${person.age}, phone: ${person.tel}`
})
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Mayvis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, so computed property will cause an type assert loop error. So I have to write another type to handle this situation.