Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow losing types when importing function which returns classes. #4312

Closed
y-sitbon opened this issue Jul 4, 2017 · 1 comment
Closed

Flow losing types when importing function which returns classes. #4312

y-sitbon opened this issue Jul 4, 2017 · 1 comment

Comments

@y-sitbon
Copy link

y-sitbon commented Jul 4, 2017

Hello!

Flow types works correctly with the code below:

/* @flow */
const movable = (Base): Class<*> => {
  return class extends Base {
    move() {
      console.log('move');
    }
  }
}

class Person {
  firstName: string;

  constructor(firstName: string) {
    this.firstName = firstName;
  }
}

const MovablePerson = movable(Person);
const p = new MovablePerson('John');

p.firstName = 1;
// Flow =>
// 22: p.firstName = 1;
//                  ^ number. This type is incompatible with
// 12:   firstName: string;
//                  ^ string

But the same code splitted into multiple .js files don't:

// Movable.js
export const movable = (Base): Class<*> => {
  return class extends Base {
    move() {
      console.log('move');
    }
  }
}

// Main.js
import {movable} from './Movable.js';

class Person {
  firstName: string;

  constructor(firstName: string) {
    this.firstName = firstName;
  }
}

const MovablePerson = movable(Person);
const p = new MovablePerson('John');

p.firstName = 1;
// Flow doesn't complain anymore but should

Hope that will help

@SamChou19815
Copy link
Contributor

These import related issues should be resolved a long time ago since types first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants