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

Static type checks doesn't seems to work #157

Closed devlato closed 7 years ago

devlato commented 8 years ago

Hey folks,

I have the following types defined:

In types.js:

export type AppStatus = 'LIVE' | 'STOPPED' | 'PENDING';
export type PlatformType = 'IOS' | 'ANDROID' | 'WP';
export type Identifier = string;
export type Timestamp = number;

export type App = {
  id : Identifier;
  name : string;
  platformType : PlatformType;
  bundleId : ?string;
  status : AppStatus;
  dateCreated : Timestamp;
};

export type AppMap = {[key : string] : App};

export type LoadableApps = {
  isWaiting : boolean,
  error : ?string,
  apps : AppMap
};

In AppService.js:

import type {Identifier, App, LoadableApps} from './types';

export default {
  setAppLoading(appId : Identifier, apps : LoadableApps) : LoadableApps {
    // Do some stuff here and return proper value of LoadableApps type
  },

  updateApp(app : App, apps : LoadableApps) : LoadableApps {
    return this.setAppLoading(app.id, apps);
  }
}

But it doesn't seems like any static analysis is being performed. Babel is correctly configured with Webpack, Typecheck plugin is also enabled and performs the required dynamic type checks, but there is no static analysis, i.e. if I pass an incorrect type argument to setAppLoading(), Typecheck won't show any warnings until I'll run the code.

What could be wrong?

ntkoopman commented 8 years ago

This plugin only provides very limited static type checking. If you want errors to also show up before running you should use Flow.

devlato commented 8 years ago

@ntkoopman Is there any possibility to run Flow with Webpack in watch mode?

ntkoopman commented 8 years ago

Flow has its own watch mode. I don't know if there is a webpack plugin.

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.

With babel-plugin-flow-runtime we don't do any static checks or optimisations at all, if it's annotated it gets checked. In practise these static checks were too difficult without reimplementing all of what flow does.