We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
比如, 一个组件的 props 很多, 但是想单独抽出来几个配置写成一个对象.
interface Person { name: string; age: number } class Person extends React.Component<Person, any> {} const age = { age: 14 } // age 为 组件的 props 的一部分, 声明这里的 type 来获取智能提示 <Person {…age} name=“哈哈” />
The text was updated successfully, but these errors were encountered:
通过截图中的信息可以看出 Partial, 并不能完美的解决这个问题,
这里在写这个对象的时候确实得到了 type 的提示
但是传递给 Person 组件的时候如果是必须的 props, 会报错误, 因为在 partial 这个变量当中是可选的.
Person
所以目前的结论是:
如果是可选的 props, 可以通过 Partial 的方式来抽离出某几个 props, 但如果是必须的, 那必须直接传递给组件
Sorry, something went wrong.
Jiang-Xuan
No branches or pull requests
比如, 一个组件的 props 很多, 但是想单独抽出来几个配置写成一个对象.
The text was updated successfully, but these errors were encountered: