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

Import type definitions do not work #110

Closed tp closed 8 years ago

tp commented 8 years ago

After hours of debugging I found #100, but I was unable to apply it in way that allows me to import type definitions.

I am currently using a self-built version of 0e51e2ff1b53eaa2f077aa53dc5462bbd3023580.

.babelrc:

{
  "presets": ["es2015", "stage-2", "react"],

  "plugins": [
    "transform-es2015-instanceof",
    ["typecheck", {
      "disable": {
        "production": true
      }
    }],
    "syntax-class-properties",
    "transform-class-properties",
    "transform-es3-property-literals",
    "syntax-async-functions",
    "transform-regenerator",
    "transform-runtime",
    "syntax-decorators",
    "transform-decorators",
    "syntax-function-bind",
    "transform-function-bind"
  ],

  "env": {
    "development": {
      "plugins": [["react-transform", {
        "transforms": [{
          "transform": "react-transform-catch-errors",
          "imports": [
            "react",
            "redbox-react"
          ]
        }, {
          "transform": "livereactload/babel-transform",
          "imports": ["react"]
        }]
      }]]
    }
  }
}

I import the type definition like this:

import type {WhiteboardProps} from './Whiteboard/Types.jsx';

But when running the code then I get an error:

LightstreamerAdapter.js:54 Uncaught TypeError: Value of argument "props" violates contract.

Expected:
WhiteboardProps

Got:
{ drawings: src_Map__Map {
  size: number;
  _root: void;
  __ownerID: void;
  __hash: void;
  __altered: boolean;
};
  texts: src_Map__Map {
  size: number;
  _root: void;
  __ownerID: void;
  __hash: void;
  __altered: boolean;
};
  currentlyEditingText: void;
  activeTool: string;
  width: number;
  height: number;
  top: number;
  zoomLevel: number;
  erasePath: Function;
  removeElement: Function;
  attendeeId: number;
  attendeeColor: string;
  attendeeName: string;
  presentationId: number;
  pageId: number;
  isTeacher: boolean;
  pageScaleFactor: number;
}

I think the "Expected" should actually list the type definition not its name if it were working, right?

phpnode commented 8 years ago

I think the "Expected" should actually list the type definition not its name if it were working, right?

Not for imported types. The only way to see whether it is working or not is to check the transformed code.

phpnode commented 8 years ago

With passPerPreset: true I'm successfully using imported types. Closing this but will reopen if it's still an issue.