热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

参数类型“X”不能赋值给参数类型“Y”-argumenttype“X”isnotassignabletoparametertype“Y”

IhaveanissuewiththewebstormIDE.Itseemslikethatwebstormalwaysshowstheerrorofinvalid

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.

我有一个关于webstorm IDE的问题。似乎webstorm总是在IDE中显示无效参数的错误,但是typescript编译器并没有显示出这样的错误;我开始相信这个问题与IDE有关。

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

我有以下存储库:https://github.com/danielmahadi/modulescript。

There are 4 typescript files:

有4个打字文件:

  • customerModel.ts => customer model file

    customerModel。客户模型文件。

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

    转换器。ts =>将json数据转换为客户模型。

    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

    打印机。ts =>打印客户模型到控制台。

    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.

    app.js =>应用程序的入口点。

    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. webstorm 7.0.3,构建数字:WS-133.434。
  3. Mac OSX with Maverick
  4. Mac OSX和特立独行的
  5. Typescript version: 0.9.5.0
  6. 打印稿版本:0.9.5.0

Typescript file watcher setting for typescript:

Typescript文件watcher设置为Typescript:

  • Typescript compiler => tsc --module commonjs --sourcemap $FileName$
  • Typescript编译器=> tsc—模块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".

如果你用webstorm IDE打开它,你会看到在app.ts第15行,“用户”总是用红线加上错误的“参数类型”。/customerModel。用户不能被分配给参数类型模型。用户。

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?

有人以前遇到过这种情况吗?我是不是做错了什么,或者这只是另一个webstorm bug?

2 个解决方案

#1


2  

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.

这绝对是webstorm的一个错误。如果你在这里报告,将会很感激:http://youtrack.jetbrains.com/es/web,并添加一个链接,以便我们对其进行投票。

#2


1  

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

请试试WebStorm 8 EAP——这个bug似乎是固定在那里的。


推荐阅读
author-avatar
手机用户2502886335
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有