Поток дает мне ошибки для определений / кода React Native. - PullRequest
0 голосов
/ 26 мая 2018

Я только начинаю с Flow и получаю кучу ошибок после его использования для сканирования проекта React Native:

Error --------------------------- node_modules

Missing type annotation for `U`.

                   v--------------------------
   353|     return range.map(function(value) {
   354|       if (typeof value !== 'string') {
   355|         return value;
   356|       }
   357|       if (/deg$/.test(value)) {
   358|         const degrees = parseFloat(value) || 0;
   359|         const radians = degrees * Math.PI / 180.0;
   360|         return radians;
   361|       } else {
   362|         // Assume radians
   363|         return parseFloat(value) || 0;
   364|       }
   365|     });
            -^


Error ------------------------------------ node_modules/react-native/Librarie

Property `update` is missing in `AnimatedNode` [1].

   node_modules/react-native/Libraries/Animated/src/nodes/AnimatedValue.js:54
   54|     if (typeof node.update === 'function') {
                      ^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Animated/src/nodes/AnimatedWithChildre
   70|   __getChildren(): Array<AnimatedNode> {
                                ^^^^^^^^^^^^ [1]


Error -------------------------------------------- node_modules/react-native/

Cannot assign `!this.props.disabled` to `props.enabled` because property `ena

   node_modules/react-native/Libraries/Components/Switch/Switch.js:105:7
   105|       props.enabled = !this.props.disabled;
              ^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Components/Switch/Switch.js:101:19
   101|     const props = {...this.props};
                          ^^^^^^^^^^^^^^^ [1]


Error -------------------------------------------- node_modules/react-native/

Cannot assign `this.props.value` to `props.on` because property `on` is missi

   node_modules/react-native/Libraries/Components/Switch/Switch.js:106:7
   106|       props.on = this.props.value;
              ^^^^^^^^

References:
   node_modules/react-native/Libraries/Components/Switch/Switch.js:101:19
   101|     const props = {...this.props};
                          ^^^^^^^^^^^^^^^ [1]


Error -------------------------------------------- node_modules/react-native/

Cannot assign `this.props.value ? this.props.onTintColor : this.props.tintCol
property `trackTintColor` is missing in object literal [1].

   node_modules/react-native/Libraries/Components/Switch/Switch.js:108:7
   108|       props.trackTintColor = this.props.value ? this.props.onTintColo
              ^^^^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Components/Switch/Switch.js:101:19
   101|     const props = {...this.props};
                          ^^^^^^^^^^^^^^^ [1]


Error ------------------------ node_modules/react-native/Libraries/Experiment

Property `setNativeProps` is missing in `React.Element` [1].

   node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableLis
   145|     if (this._listViewRef && typeof this._listViewRef.setNativeProps
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableLis
    58|   _listViewRef: ?React.Element<any> = null;
                         ^^^^^^^^^^^^^^^^^^ [1]


Error ------------------------ node_modules/react-native/Libraries/Experiment

Property `getScrollResponder` is missing in `React.Element` [1].

   node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableLis
   154|     if (this._listViewRef && typeof this._listViewRef.getScrollRespon
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Experimental/SwipeableRow/SwipeableLis
    58|   _listViewRef: ?React.Element<any> = null;
                         ^^^^^^^^^^^^^^^^^^ [1]


Error ----------------------------------------------- node_modules/react-nati

Cannot assign array literal to `scrollProps.style` because property `style` i

   node_modules/react-native/Libraries/Lists/VirtualizedList.js:908:7
   908|       scrollProps.style = [inversionStyle, this.props.style];
              ^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Lists/VirtualizedList.js:893:25
                                v
   893|     const scrollProps = {
   894|       ...this.props,
   895|       onContentSizeChange: this._onContentSizeChange,
   896|       onLayout: this._onLayout,
   897|       onScroll: this._onScroll,
   898|       onScrollBeginDrag: this._onScrollBeginDrag,
   899|       onScrollEndDrag: this._onScrollEndDrag,
   900|       onMomentumScrollEnd: this._onMomentumScrollEnd,
   901|       scrollEventThrottle: this.props.scrollEventThrottle, // TODO: A
   902|       invertStickyHeaders: this.props.invertStickyHeaders !== undefin
   903|         ? this.props.invertStickyHeaders
   904|         : this.props.inverted,
   905|       stickyHeaderIndices,
   906|     };
            ^ [1]


Error --------------------------------------------- node_modules/react-native

Property `inLayout` is missing in object type [1].

   node_modules/react-native/Libraries/Lists/VirtualizedList.js:1125:11
   1125|       if (frame.inLayout) {
                   ^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Lists/VirtualizedList.js:1474:6
   1474|   ): {length: number, offset: number} => {
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Error --------------------------------------------- node_modules/react-native

Property `debug` is missing in object type [1].

   node_modules/react-native/Libraries/Lists/VirtualizedList.js:1649:25
   1649|       getItemLayout && !parentProps.debug && !fillRateHelper.enabled
                                 ^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/Lists/VirtualizedList.js:1567:18
                          v
   1567|     parentProps: {
   1568|       getItemLayout?: ?Function,
   1569|       renderItem: renderItemType,
   1570|     },
             ^ [1]


Error ----------------------------------------------- node_modules/react-nati

Property `disableYellowBox` is missing in object type [1].

   node_modules/react-native/Libraries/ReactNative/YellowBox.js:108:7
   108|   if (console.disableYellowBox) {
              ^^^^^^^^^^^^^^^^^^^^^^^^

References:
   C:\cygwin64\tmp\flow\flowlib_1ec88eef\core.js:806:22
                             v-
   806| declare var console: {
   807|   assert(condition: mixed, ...data: Array<any>): void;
   808|   clear(): void;
   809|   count(label: string): void;
   810|   debug(...data: Array<any>): void;
   811|   dir(...data: Array<any>): void;
   812|   dirxml(...data: Array<any>): void;
   813|   error(...data: Array<any>): void;
   814|   _exception(...data: Array<any>): void;
   815|   group(...data: Array<any>): void;
   816|   groupCollapsed(...data: Array<any>): void;
   817|   groupEnd(): void;
   818|   info(...data: Array<any>): void;
   819|   log(...data: Array<any>): void;
   820|   profile(name?: string): void;
   821|   profileEnd(name?: string): void;
   822|   table(tabularData: { [key: string]: any } | Array<{ [key: string]:
   823|   time(label: string): void;
   824|   timeEnd(label: string): void;
   825|   timeStamp(label?: string): void;
   826|   trace(...data: Array<any>): void;
   827|   warn(...data: Array<any>): void;
   828| };
        ^ [1]


Error ---------------------------------------------- node_modules/react-nativ

Property `ignoredYellowBox` is missing in object type [1].

   node_modules/react-native/Libraries/ReactNative/YellowBox.js:181:19
   181|     Array.isArray(console.ignoredYellowBox) &&
                          ^^^^^^^^^^^^^^^^^^^^^^^^

References:
   C:\cygwin64\tmp\flow\flowlib_1ec88eef\core.js:806:22
                             v-
   806| declare var console: {
   807|   assert(condition: mixed, ...data: Array<any>): void;
   808|   clear(): void;
   809|   count(label: string): void;
   810|   debug(...data: Array<any>): void;
   811|   dir(...data: Array<any>): void;
   812|   dirxml(...data: Array<any>): void;
   813|   error(...data: Array<any>): void;
   814|   _exception(...data: Array<any>): void;
   815|   group(...data: Array<any>): void;
   816|   groupCollapsed(...data: Array<any>): void;
   817|   groupEnd(): void;
   818|   info(...data: Array<any>): void;
   819|   log(...data: Array<any>): void;
   820|   profile(name?: string): void;
   821|   profileEnd(name?: string): void;
   822|   table(tabularData: { [key: string]: any } | Array<{ [key: string]:
   823|   time(label: string): void;
   824|   timeEnd(label: string): void;
   825|   timeStamp(label?: string): void;
   826|   trace(...data: Array<any>): void;
   827|   warn(...data: Array<any>): void;
   828| };
        ^ [1]


Error ----------------------------------------------- node_modules/react-nati

Property `disableYellowBox` is missing in object type [1].

   node_modules/react-native/Libraries/ReactNative/YellowBox.js:382:9
   382|     if (console.disableYellowBox || this.state.warningMap.size === 0)
                ^^^^^^^^^^^^^^^^^^^^^^^^

References:
   C:\cygwin64\tmp\flow\flowlib_1ec88eef\core.js:806:22
                             v-
   806| declare var console: {
   807|   assert(condition: mixed, ...data: Array<any>): void;
   808|   clear(): void;
   809|   count(label: string): void;
   810|   debug(...data: Array<any>): void;
   811|   dir(...data: Array<any>): void;
   812|   dirxml(...data: Array<any>): void;
   813|   error(...data: Array<any>): void;
   814|   _exception(...data: Array<any>): void;
   815|   group(...data: Array<any>): void;
   816|   groupCollapsed(...data: Array<any>): void;
   817|   groupEnd(): void;
   818|   info(...data: Array<any>): void;
   819|   log(...data: Array<any>): void;
   820|   profile(name?: string): void;
   821|   profileEnd(name?: string): void;
   822|   table(tabularData: { [key: string]: any } | Array<{ [key: string]:
   823|   time(label: string): void;
   824|   timeEnd(label: string): void;
   825|   timeStamp(label?: string): void;
   826|   trace(...data: Array<any>): void;
   827|   warn(...data: Array<any>): void;
   828| };
        ^ [1]


Error ---------------------------------------- node_modules/react-native/Libr

Property `prototype` is missing in `React.StatelessFunctionalComponent` [1].

   node_modules/react-native/Libraries/ReactNative/renderApplication.js:41:5
   41|     RootComponent.prototype != null &&
           ^^^^^^^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/ReactNative/renderApplication.js:24:18
   24|   RootComponent: React.ComponentType<Props>,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Error --------------------------------- node_modules/react-native/Libraries/R

Property `__propTypesSecretDontUseThesePlease` is missing in `React.Stateless

   node_modules/react-native/Libraries/ReactNative/requireNativeComponent.js:
   122|         typeof componentInterface.__propTypesSecretDontUseThesePlease
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
   node_modules/react-native/Libraries/ReactNative/requireNativeComponent.js:
    50|   componentInterface?: ?ComponentInterface,
                                ^^^^^^^^^^^^^^^^^^ [1]


Error -----------------------------------------------------------------------

Моя версия Flow - 0.72.0, а моя ReactРодная версия 0.55.3.Что я могу делать не так?

1 Ответ

0 голосов
/ 19 июня 2018

Array.map метод в lib.es5.d.ts аннотирован как

map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];

Существует общий тип U для представления типа элементов массива, возвращаемых этим методом после отображения.

Когда Flow жалуется на Missing type annotation for `U`., это наиболее вероятно, потому что Flow по какой-то причине не может автоматически определить этот тип, и вы должны объявить его явно:

function XXX(YYYY): (some_type | number)[] { // <-- you should explicitly declare return type here
  ...

  return range.map(function(value: some_type|string) { // <--- probably, more explicit typehint here as well
    if (typeof value !== 'string') {
      return value; // <-- return value is a 'some_type' here
    }
    if (/deg$/.test(value)) {
      const degrees = parseFloat(value) || 0;
      const radians = degrees * Math.PI / 180.0;
      return radians; // <-- return value is 'number' here
    } else {
      // Assume radians
      return parseFloat(value) || 0; // <-- return value is 'number' here
    }
  });
}

Остальные ошибки в основном происходят изОпределения типов React, так как они имеют неполное покрытие для существующих свойств объектов элементов / узлов DOM (например, readonly и т. Д.) И типовых указаний ReactNative, поскольку они часто являются неполными.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...