2017-06-06 11 views
2

Flow mir zu sagen, dass ein explizit übergebene String mit null unvereinbar ist, und es scheint, etwas zu haben, mit einem Explosions Objekt zu tun, auch in weitergegeben werden.flowtype- String ist nicht kompatibel mit null

Ich habe die folgend in meiner reagieren Bootstrap-Bibliothek Schnittstelle Definitionsdatei:

declare export type FormControlProps = {| 
    componentClass?: ?componentClass, 
    // componentClass is an enum of strings 'select' | 'div' etc 
    // There are other params here, too. 
|} 

und die folgenden in einer Komponente:

import { FormControl, type FormControlProps } from 'react-bootstrap'; 

type EnumSelectProps = {| 
    defaultText: string, 
    ...FormControlProps, 
|}; 

// and in the render method: 
    const { defaultText, ...other: FormControlProps } = this.props; 

    <FormControl 
    {...other} 
    componentClass="select" 
    value={this.state.value} 
    onChange={event => this.onChange(event.target.value)} 
    > 
    { children } 
    </FormControl> 

Dies scheint in Ordnung zu sein, nicht wahr? ...other hat den Typ FormControlProps. Ich bekomme jedoch die Beschwerde:

  v----------- 
43:  <FormControl 
44:   {...other} 
45:   componentClass="select" 
...: 
48:  > 
     ^props of React element `FormControl` 
45:   componentClass="select" 
          ^^^^^^^^ string. This type is incompatible with 
463:  componentClass?: ?componentClass, 
          ^^^^^^^^^^^^^^^ null. See lib: flow-typed/npm/react-bootstrap_v0.x.x.js:463 

Was gibt? Wenn ich other als any (d. H. ...(other: any)) einstelle, funktioniert es. Auch wenn ich only left-hand optional componentClass?: componentClass mache, funktioniert es. (Das ist jedoch nicht die richtige Definition.) Gibt es einen weniger hacky Weg damit umzugehen? Vielen Dank!

Antwort

Verwandte Themen