Подтвердить что ты не робот

StyleSheet.create "не покрывается потоком"

Я использую поток 0.42.0 в реактивном нативном проекте с нуклидом.

С проектом по умолчанию я получаю следующее сообщение:

введите описание изображения здесь

Наряду со следующими ошибками:

> flow check
index.ios.js:40
 40:             <View style={style.container}>
                                    ^^^^^^^^^ property `container`. Property cannot be accessed on possibly undefined value
 40:             <View style={style.container}>
                              ^^^^^ undefined

index.ios.js:40
 40:             <View style={style.container}>
                                    ^^^^^^^^^ property `container`. Property not found in
 40:             <View style={style.container}>
                              ^^^^^ Array

index.ios.js:41
 41:                 <Text style={style.welcome}>
                                        ^^^^^^^ property `welcome`. Property cannot be accessed on possibly undefined value
 41:                 <Text style={style.welcome}>
                                  ^^^^^ undefined

index.ios.js:41
 41:                 <Text style={style.welcome}>
                                        ^^^^^^^ property `welcome`. Property not found in
 41:                 <Text style={style.welcome}>
                                  ^^^^^ Array

index.ios.js:44
 44:                 <Text style={style.instructions}>
                                        ^^^^^^^^^^^^ property `instructions`. Property cannot be accessed on possibly undefined value
 44:                 <Text style={style.instructions}>
                                  ^^^^^ undefined

index.ios.js:44
 44:                 <Text style={style.instructions}>
                                        ^^^^^^^^^^^^ property `instructions`. Property not found in
 44:                 <Text style={style.instructions}>
                                  ^^^^^ Array

index.ios.js:47
 47:                 <Text style={style.instructions}>
                                        ^^^^^^^^^^^^ property `instructions`. Property cannot be accessed on possibly undefined value
 47:                 <Text style={style.instructions}>
                                  ^^^^^ undefined

index.ios.js:47
 47:                 <Text style={style.instructions}>
                                        ^^^^^^^^^^^^ property `instructions`. Property not found in
 47:                 <Text style={style.instructions}>
                                  ^^^^^ Array


Found 8 errors

Эта проблема (https://github.com/flowtype/flow-typed/issues/631) показала, что правильный тип был StyleSheet.Styles, но это дает мне то же сообщение (и те же ошибки сверху):

введите описание изображения здесь

Есть ли способ, которым я могу работать с правильной машиной ввода?

Для справки, полный файл:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

export default class PartalkReact extends Component {
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>
                    Welcome to React Native!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit index.ios.js
                </Text>
                <Text style={styles.instructions}>
                    Press Cmd+R to reload,{'\n'}
                    Cmd+D or shake for dev menu
                </Text>
            </View>
        );
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('PartalkReact', () => PartalkReact);

Изменить. После обновления до потока 0.45.0, как и в комментариях, у меня больше нет проблем с моими файлами, но я не могу справиться со следующими ошибками: https://pastebin.com/raw/Ngpagayi

4b9b3361

Ответ 1

Предупреждение происходит из-за того, что третья сторона не интегрировала поток до конца. В нашем случае StyleSheet дает предупреждение, так что реагировать на родной - это третья сторона, которая не интегрировала поток. Реагировать только родной поток в некоторых компонентах может быть только основным, и он был официально объявлен ими.

Как сказал вам, что response-native использует поток в таблице стилей, поэтому я пришел к выводу:

import type { StyleObj } from 'react-
native/Libraries/StyleSheet/StyleSheetTypes';

type Props = {
    style?: StyleObj,
};

Другой способ - обновить поток.

Приветствия:)

Ответ 2

Для тех, кто все еще сталкивался с этим в конце 2018 года, предпочтительное решение изменилось на:

import type {
  ViewStyleProp,
  TextStyleProp,
  ImageStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet';

Источник: https://github.com/flow-typed/flow-typed/issues/631

Ответ 3

Я использовал следующее для довольно хорошего успеха
Это покажет ошибки, если вы используете несуществующие свойства стиля и включите завершение кода

const rawStyles = { ... }
export const styles: typeof rawStyles = StyleSheet.create(rawStyles)

Ответ 4

Добавьте это выше вашего класса:

type Props = {
    style?: StyleSheet.Styles;
};