facebook / facebook/flow

What is correct way to declare custom class factory?

Open
#3,934 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello!
I'm searched, but not found answer on the similar question. Sorry if issue like this already exists.

When we [declare React-class](https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoAbgQwE5gEoCmmAxgC5gC8Y2BAjgK4CWNAFAOQ0mlsCUA3KkJcAdMU6kCAYRiYAzrJYBvVGFVhicAHaaCZFjzDK1x9Vtnl62GAC4wm+gFsARgVxVSAC0azhAcwKkAKpW+gLGAL4ANCpq-kEhPLbm2IyavoYxJtQBlppgbGxhauGo4fyoQA):
```
/* @flow */
var React = require('react');
React.createClass({
connect() {
const url: number = this.getUrl();
},
getUrl(): string {
return '';
}
});
```

Flow throws expected errors:
```
5: const url: number = this.getUrl();
^ string. This type is incompatible with
5: const url: number = this.getUrl();
^ number
```

But when we [declare our custom class factory](https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoAJgUwMYwIYBOmYueAzmWALICeYA3qmGGQC56sCW2JRHmAYXwUAPAAUAfAAoADgTgyyALjBiAlCqHky4iQG5UAX1S0AdNj6tBwslMbNm2OADtnOVlLUMmD30+dsYACuBDAqzkEAtgBGmARgALxgrAAWnGSmAOaYrACqoZ4GvoYAND7M2XkFGiysBJzOmd6+vkSsIc5gAORdRQ7GhmoGQA):
```
/* @flow */
declare class My {
static createClass

(props: P): Class

;
}
My.createClass({
connect() {
const url: number = this.getUrl();
},
getUrl(): string {
return '';
}
});
```

Flow says that it's `No errors!`. Why? How we can describe declaration to achieve the same behaviour as `React.createClass`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.