2016-11-17 23 views
10

children'u açıklamak için daha iyi bir yol var mı?akış tipi ek açıklamaları

type FilterLinkProps={ 
    filter:State$VisibilityFilter, 
    children:any 
}; 

const FilterLink = ({ 
    filter, 
    children 
}:FilterLinkProps) => { 
    return (
    <a href='#' 
     onClick={e => { 
     e.preventDefault(); 
     store.dispatch(({ 
      type: 'SET_VISIBILITY_FILTER', 
      filter 
     }:Action$VisibilityFilter)); 
     }} 
    > 
    {children} 
    </a> 
); 
}; 

cevap

8

Böyle görünmüyor. Resmi React libdef itibaren

:

declare module react { 
    declare var Children: any; 
    ... 
} 

ve sonra

declare function cloneElement<Config> (
    element: React$Element<Config>, 
    attributes: $Shape<Config>, 
    children?: any 
): React$Element<Config>; 
23

Akış v0.53 kutudan children destekler !!

import * as React from 'react'; 

type Props = { 
    children?: React.Node, 
}; 

diğer bilgiler official docs veya bu konuda şu blog post okuyun. eski sürümleri aşağıdakileri yapabilirsiniz akış için

:

import React from 'react'; 
import type { Children } from 'react'; 
type Props = { 
    children?: Children, 
}; 
const SampleText = (props: Props) => (
    <div>{props.children}</div> 
); 

Her iki durumda children bir nullable türü olarak beyan edilmelidir.

Bazı parçaları lifin gelmesiyle ileriye taşıyacak gibi görünüyorlar, umarlar! github

Hile levha ile yapılan görüşmenin ardından

:http://www.saltycrane.com/blog/2016/06/flow-type-cheat-sheet/

0
type Text = string | number; 
type Fragment = Iterable<Node>; 
type ReactNode = React$Element<any> 
    | Text 
    | Fragment; 

ReactNode çocukların tipi, ancak ihtar emptor olmalıdır.

Kaynak: Bu inşayı akış repolarındaki bazı github sorunlarında gördüm.

İlgili konular