Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

argument type "X" is not assignable to parameter type "Y"

I have an issue with the webstorm IDE. It seems like that webstorm always shows the error of invalid argument in the IDE, but the typescript compiler do not show such error; I'm starting to believe that this issue is with the IDE.

I have the following repository: https://github.com/danielmahadi/modular-typescript

There are 4 typescript files:

  • customerModel.ts => customer model file

    export class User{
        constructor(public id: string, public name: string){}
    }
    
  • converter.ts => convert json data to customer model

    import model = require('./customerModel')
    
    export function convertToUser(data: any) : model.User {
        return new model.User(data.id, data.name);
    }
    
  • printer.ts => print the customer model to console

    import model = require('./customerModel')
    
    export function print(data : model.User) : void {
        console.log('PRINTING...');
        console.log(data);
    }
    
  • app.js => the entry point for the app.

    import converter = require('./converter');
    import printer = require('./printer');
    
    var d = {
        id: '123', name: 'Test'
    }
    
    var user = converter.convertToUser(d);
    printer.print(user);
    

Environment:

  1. webstorm 7.0.3, build number: WS-133.434
  2. Mac OSX with Maverick
  3. Typescript version: 0.9.5.0

Typescript file watcher setting for typescript:

  • Typescript compiler => tsc --module commonjs --sourcemap $FileName$

If you open this with webstorm IDE, you will see that in the app.ts line 15, the "user" is always underlined with red line with the error "Argument type './customerModel'.User is not assignable to parameter type model.User".

This is what the error looks like:

Has anyone else encountered this before? Am I doing something wrong, or this is just another webstorm bug?

like image 470
Daniel Mahadi Avatar asked Oct 20 '22 12:10

Daniel Mahadi


2 Answers

Definitely an error in webstorm. Would appreciate it if you report it here : http://youtrack.jetbrains.com/issues/WEB and put a link so we can vote on it.

like image 102
basarat Avatar answered Oct 23 '22 04:10

basarat


Please try WebStorm 8 EAP - the bug seems to be fixed there

like image 35
lena Avatar answered Oct 23 '22 06:10

lena