Skip to content

Functional components type error ts2322 #68

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

Closed
nicefan opened this issue May 28, 2019 · 4 comments
Closed

Functional components type error ts2322 #68

nicefan opened this issue May 28, 2019 · 4 comments

Comments

@nicefan
Copy link

nicefan commented May 28, 2019

<VIf condition={true}>

不能将类型“{ condition: boolean | undefined; }”分配给类型“{ props: any; }”。
类型“{ props: any; }”上不存在属性“condition”。ts(2322)

如果改成 (ctx)=><div>ctx.props.condition</div> 没问题
这种写法在非jsx中 注册到components中的时候控制台也会报类型错误,但不影响编译

@haoqunjiang
Copy link
Member

能否提供可以运行的复现?没太懂你的问题

@nicefan
Copy link
Author

nicefan commented May 28, 2019

functional component
name.tsx

export default ({props})=><div>props.value</div>

used.tex

import Name from './name'
...
render () {
  return (
    <div><Name value={this.fullname} /></div>
  )
}
...

这样Name 标签就会报类型错误:

不能将类型“{ value: string | undefined; }”分配给类型“{ props: any; }”。
类型“{ props: any; }”上不存在属性“value”。ts(2322)

@haoqunjiang
Copy link
Member

你需要给 props 加上类型声明,这是正常报错。

@haoqunjiang
Copy link
Member

哦我知道了,你应该是碰上了这个问题 vuejs/vue-cli#2417
请使用 vue-tsx-support https://github.com/wonderful-panda/vue-tsx-support

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

No branches or pull requests

2 participants