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

Not returning a value #52

Closed mazzy89 closed 8 years ago

mazzy89 commented 8 years ago

This is my .babelrc config file:

{
  "plugins": [
    "typecheck",
    "transform-async-to-generator"
  ]
}

while this is my code:

'use strict'

const Koa = require('koa')
const app = new Koa()

// define logger - this will be always executed
const logger = async (context, next) => {
  const start = new Date()
  await next()
  const ms = new Date() - start
  console.log(`${context.method} ${context.url} - ${ms}ms`)
}

// this will be always executed
const index = (context) => {
  context.body = foo()
}

function foo (): boolean {
  if (Math.random() > 0.5) {
    return true
  } else {
    return false
  }
}

app.use(logger)
app.use(index)

app.listen(3000)
console.info(`The app is listening on port 3000`)

whatever function I try to verify I get always an error like this:

Function "foo" did not return a value, expected bool

I have tried with different function but always a similar error.

phpnode commented 8 years ago

@mazzy89 this is now fixed in 3.0.2, please verify.

mazzy89 commented 8 years ago

@phpnode still doesn't work. this is the error I get:

error given was: SyntaxError: /Users/mazzy/vagrant-devbox/koa-project/src/server.js: Unexpected token (24:15)
  22 | }
  23 |
> 24 | function foo (): boolean {
     |                ^
  25 |   if (Math.random() > 0.5) {
  26 |     return true
  27 |   } else {
phpnode commented 8 years ago

@mazzy89 that's a different issue, either because babel-plugin-syntax-flow isn't enabled or because you're not stripping flow types after compilation (babel-plugin-transform-flow-strip-types). Please could you post your package.json and .babelrc ?

mazzy89 commented 8 years ago

this is my package.json:

{
  "name": "koa-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": ">= 4"
  },
  "scripts": {
    "dev": "better-npm-run dev"
  },
  "betterScripts": {
    "dev": {
      "command": "node bin/server",
      "env": {
        "NODE_CONFIG_DIR": "./src/config"
      }
    }
  },
  "keywords": [],
  "author": "mazzy89 <apocalipse89@gmail.com>",
  "license": "MIT",
  "dependencies": {
    "config": "1.17.1",
    "koa": "2.0.0-alpha.3",
    "koa-logger": "2.0.0",
    "piping": "0.3.0"
  },
  "devDependencies": {
    "babel-core": "6.2.1",
    "babel-eslint": "4.1.5",
    "babel-plugin-transform-async-to-generator": "6.1.18",
    "babel-plugin-typecheck": "3.0.2",
    "better-npm-run": "0.0.4",
    "eslint": "1.9.0",
    "eslint-config-airbnb": "1.0.0",
    "eslint-config-standard": "4.4.0",
    "eslint-plugin-react": "3.9.0",
    "eslint-plugin-standard": "1.3.1"
  }
}

and this is babelrc

{
  "plugins": [
    "typecheck",
    "transform-async-to-generator"
  ]
}
phpnode commented 8 years ago

@mazzy89 please see the section I added to the README in #56