简体   繁体   English

如何使用FlowType继承类?

[英]How do I inherit class with FlowType?

Use React(ReactNative). 使用React(ReactNative)。

Want to inherit Component class, but in that case happen trouble with flow error. 要继承Component类,但在这种情况下会发生流错误的麻烦。

TryFlow TryFlow

/* @flow */

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

type commonProps ={
  actions: Object,
};

type someProps = commonProps & {
  someNumber: number,
};

class CustomComponent extends Component<commonProps> {
  static defaultProps: {};
  props: commonProps;
}

class MyComponent extends CustomComponent {
  props: someProps;

  render() {
    return (
      <Text>{this.props.someNumber}</Text>
    );
  }
}

What to do??? 该怎么办???

I guess you should set type annotation for classes. 我猜你应该为类设置类型注释。 Like this: 像这样:

class CustomComponent<commonProps> extends Component<Props, State> {
   static defaultProps: {};
   props: commonProps;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何允许对象从其类继承成员? - How do I allow objects to inherit members from their class? 在JavaScript中,如何使用单个“ .prototype”块从子类的父类继承? - In JavaScript, how do I inherit from a parent class in child class using a single “.prototype” block? 如何使用对象伪造类实例(并且仍然使flowtype验证接口)? - How can I fake a class instance using an object (and still have flowtype verify the interface)? 在带有flowtype的React中,我如何只键入某些道具并允许其他任何道具 - In React with flowtype how do I type only certain props and allow any others 如何在不重复类型说明的情况下在类及其默认值上重用流类型定义? - How can I re-use a flowtype type definition on a class and its defaults without duplicating the type specification? 如何在流类型接口上对类的构造函数参数进行严格的类型检查? - How do I get strict type checking on flowtype interfaces to constructor arguments for classes? 如何使用原型继承变量? - How do I inherit a variable with prototype? 我如何继承javascript函数? - How do I inherit javascript functions ? 如何在javascript中继承2个类 - How to inherit 2 Class in javascript 如何在javascript中继承Class? - How to inherit Class in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM