Skip to content
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

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/flex/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Copy link
Contributor

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?

Copy link
Contributor Author

@cncolder cncolder Jun 14, 2017

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> { }

Copy link
Contributor Author

@cncolder cncolder Jun 14, 2017

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'.'

Copy link
Contributor

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[] 合理

disabled?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion components/list/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NativeProps, WebProps } from '../baseType';
export interface ListProps {
renderHeader?: Function | JSX.Element;
renderFooter?: Function | JSX.Element;
children?: JSX.Element;
children?: JSX.Element | JSX.Element[];
}

export interface ListWebProps extends WebProps, ListProps {
Expand Down