-
-
Notifications
You must be signed in to change notification settings - Fork 50.6k
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
add a generic type for FormCreateOption
#7119
add a generic type for FormCreateOption
#7119
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7119 /- ##
==========================================
Coverage 85.87% 85.87% <.01%
==========================================
Files 231 231
Lines 4955 4957 2
Branches 1413 1415 2
==========================================
Hits 4255 4257 2
Misses 700 700
Continue to review full report at Codecov.
|
LGTM. const mapPropsToFields = (props: ArticleDetailOwnProps) => props ...//
const onFieldsChange = (props, fields) => null
const ArticleDetailForm = Form.create<TOwnProps>({ onFieldsChange, mapPropsToFields })(ArticleDetail) |
@BANG88 Of course, because when you define a function (or arrow function), the compiler has no idea where it will be, so the params is free to declare. But when you put the function to another function as a param (like |
Maybe not, only useful when you write function inside options, otherwise we don't know the type definitions. |
你可能没有理解我的意思,我用中文表达吧。 你在定义一个函数的时候,参数的类型肯定是自由的。但是当这个函数是用作参数的话,就是有限制的了。 比如: const mapPropsToFields = (props) => {
return {
}
}
export default Form.create<ICommentFormProps>({
mapPropsToFields
})(CommentForm) 这样编译器不会认为错,是因为 props 默认就是 但是如果你传一个不是 所以如果你需要把函数在外定义,编译器只能保证这个函数作为参数传递时它接受的参数的类型是安全的 (除了any),至于 Intelisense, 就只能靠你手动声明类型了: const mapPropsToFields = (props: TOwnProps) => {
return {
}
} |
嗯 定义在外面需要手动添加类型。 |
conflict |
resovled |
By adding a generic type for
FormCreateOption
, we can now know what type the props inmapPropsToFields
,onFieldsChange
,onValuesChange
is.