2017-10-24 40 views
0

I次のコンポーネントを持っていると私はプロパティのいずれかを検証したいが、私はこのエラーを取得プロパティ「propTypes」タイプに存在しません「typeof演算FactoryMethod

プロパティ

『propTypes』のタイプに存在しません」typeof演算FactoryMethod

それはUpdate 1のドキュメント

//#region Imports 
import * as React from "react"; 
import styles from "./FactoryMethod.module.scss"; 
import { IFactoryMethodProps } from "./IFactoryMethodProps"; 
import { 
    IDetailsListItemState, 
    IDetailsNewsListItemState, 
    IDetailsDirectoryListItemState, 
    IDetailsAnnouncementListItemState, 
    IFactoryMethodState 
} from "./IFactoryMethodState"; 
import { IListItem } from "./models/IListItem"; 
import { IAnnouncementListItem } from "./models/IAnnouncementListItem"; 
import { INewsListItem } from "./models/INewsListItem"; 
import { IDirectoryListItem } from "./models/IDirectoryListItem"; 
import { escape } from "@microsoft/sp-lodash-subset"; 
import { SPHttpClient, SPHttpClientResponse } from "@microsoft/sp-http"; 
import { ListItemFactory} from "./ListItemFactory"; 
import { TextField } from "office-ui-fabric-react/lib/TextField"; 
import { 
    DetailsList, 
    DetailsListLayoutMode, 
    Selection, 
    IColumn 
} from "office-ui-fabric-react/lib/DetailsList"; 
import { MarqueeSelection } from "office-ui-fabric-react/lib/MarqueeSelection"; 
import { autobind } from "office-ui-fabric-react/lib/Utilities"; 
import PropTypes from "prop-types"; 
//#endregion 


export default class FactoryMethod extends React.Component<IFactoryMethodProps, IFactoryMethodState> { 
    private listItemEntityTypeName: string = undefined; 
    private _selection: Selection; 

    constructor(props: IFactoryMethodProps, state: any) { 
    super(props); 
    this.setInitialState(); 
    this._configureWebPart = this._configureWebPart.bind(this); 
    } 


    public componentWillReceiveProps(nextProps: IFactoryMethodProps): void { 
    this.listItemEntityTypeName = undefined; 
    this.setInitialState(); 
    } 

    public componentDidMount(): void { 
    this.readItemsAndSetStatus(); 
    } 

    public setInitialState(): void { 
    this.state = { 
     type: "ListItem", 
     status: this.listNotConfigured(this.props) 
     ? "Please configure list in Web Part properties" 
     : "Ready", 
     DetailsListItemState:{ 
     columns:[], 
     items:[] 
     }, 
     DetailsNewsListItemState:{ 
     columns:[], 
     items:[] 
     }, 
     DetailsDirectoryListItemState:{ 
     columns:[], 
     items:[] 
     }, 
     DetailsAnnouncementListItemState:{ 
     columns:[], 
     items:[] 
     }, 
    }; 
    } 

    private _configureWebPart(): void { 
    this.props.configureStartCallback(); 
    } 

    // reusable inline component 
    public ListMarqueeSelection = (itemState: {columns: IColumn[], items: IListItem[] }) => (
     <div> 
     <MarqueeSelection selection={ this._selection }> 
      <DetailsList 
      items={ itemState.items } 
      columns={ itemState.columns } 
      setKey="set" 
      layoutMode={ DetailsListLayoutMode.fixedColumns } 
      selection={ this._selection } 
      selectionPreservedOnEmptyClick={ true } 
      compact={ true }> 
      </DetailsList> 
     </MarqueeSelection> 
     </div> 
) 

    public render(): React.ReactElement<IFactoryMethodProps> { 
     this.readItemsAndSetStatus(); 
     switch(this.props.listName)  { 
      case "GenericList": 
      // tslint:disable-next-line:max-line-length 
      return <this.ListMarqueeSelection items={this.state.DetailsListItemState.items} columns={this.state.DetailsListItemState.columns} />; 
      case "News": 
      // tslint:disable-next-line:max-line-length 
      return <this.ListMarqueeSelection items={this.state.DetailsNewsListItemState.items} columns={this.state.DetailsNewsListItemState.columns}/>; 
      case "Announcements": 
      // tslint:disable-next-line:max-line-length 
      return <this.ListMarqueeSelection items={this.state.DetailsAnnouncementListItemState.items} columns={this.state.DetailsAnnouncementListItemState.columns}/>; 
      case "Directory": 
      // tslint:disable-next-line:max-line-length 
      return <this.ListMarqueeSelection items={this.state.DetailsDirectoryListItemState.items} columns={this.state.DetailsDirectoryListItemState.columns}/>; 
      default: 
      return null; 
     } 
    } 

    // read items using factory method pattern and sets state accordingly 
    private readItemsAndSetStatus(): void { 

    this.setState({ 
     status: "Loading all items..." 
    }); 

    const factory: ListItemFactory = new ListItemFactory(); 
    const items: IListItem[] = factory.getItems(this.props.spHttpClient, this.props.siteUrl, this.props.listName); 
    const keyPart: string = this.props.listName === "GenericList" ? "" : this.props.listName; 
    if(items != null ) 
    { 
     // the explicit specification of the type argument `keyof {}` is bad and 
     // it should not be required. 
     this.setState<keyof {}>({ 
     status: `Successfully loaded ${items.length} items`, 
     ["Details" + keyPart + "ListItemState"] : { 
      items, 
      columns: [ 
      ] 
     } 
     }); 
    } 

    } 

    private listNotConfigured(props: IFactoryMethodProps): boolean { 
    return props.listName === undefined || 
     props.listName === null || 
     props.listName.length === 0; 
    } 
} 

FactoryMethod.propTypes = { 
    listName: React.PropTypes.oneOf(["GenericList","Announcements","News"]) 
} 

に応じて私にOKになります。

enter image description here

アップデート2

IFactoryMethodProps

import { SPHttpClient } from "@microsoft/sp-http"; 
import IDataProvider from "./dataproviders/IDataProvider"; 

export interface IFactoryMethodProps { 
    listName: string; 
    spHttpClient: SPHttpClient; 
    siteUrl: string; 
    dataProvider: IDataProvider; 
    configureStartCallback:() => void; 
} 

答えて

1

私は、あなたがすべきだと思う:

 ⌄ 
import type { IFactoryMethodProps } from "./IFactoryMethodProps"; 

あなたはタイプの別名をインポートしているように見えるので。

https://flow.org/en/docs/types/modules/

+0

ない私は# –

+0

は 'タイプを追加し理解してください:一番下に、次に

class FactoryMethod 

これを行います'あなたがタイプエイリアスをインポートしている場合は、インポート前のキーワード(私は小さな矢印を作った) – David

+0

また@LuisValencia:あなたは私たちにできる'propTypes'の代わりに' static defaultProps'を実行します。https://flow.org/en/docs/react/components/ – David

1

あなたがpropTypesを取り付ける前に、エクスポートされる可能性がありますかのように見えます。これに

export default class FactoryMethod 

は、この変更しようと

FactoryMethod.propTypes = { 
    listName: React.PropTypes.oneOf(["GenericList","Announcements","News"]) 
} 

export default FactoryMethod; 
+0

私はまだ同じエラーが出ることを試みました:プロパティ 'propType'が型 'factoryMethod'に存在しません –

+0

'IFactoryMethodProps'に' propTypes'の型定義がありますか? –

+0

そのインターフェースコードでアップデート2を見てください。ごめんなさい。 (おそらくチュートリアルで明確ではない) –

関連する問題