codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Support for React classes #135

Closed okonet closed 7 years ago

okonet commented 8 years ago

I think this was working in 3.6.1 but it isn't anymore in 3.8.0

import React from 'react'

export default class extends React.Component {

    props: {
        children: React.Component
    }
phpnode commented 8 years ago

Please see the discussion in #125, do you get an error or just no validation?

ntkoopman commented 8 years ago

You will get a prop validation error because children is not an instance of a React.Component, but is instead a ReactElement. Those don't have a prototype though, so you will have to define a custom type or use Object.

okonet commented 8 years ago

@ntkoopman how to define a custom type for it? Any examples?

phpnode commented 8 years ago

@okonet you can create a simplified copy of the definition at https://github.com/facebook/flow/blob/master/lib/react.js#L111

e.g.

type React$Element = {
  type: Function;
  props: Object;
  key: ?string;
  ref: any;
};
phpnode commented 7 years ago

Hi, sorry for taking so long to respond to this, this project is now deprecated in favour of https://codemix.github.io/flow-runtime which aims for full compatibility with Flow.

babel-plugin-flow-runtime and flow-runtime have full support for React.