简体   繁体   English

参数类型“Y”不能赋值参数类型“Y”

[英]argument type “X” is not assignable to parameter type “Y”

I have an issue with the webstorm IDE. 我有一个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; 似乎webstorm总是在IDE中显示无效参数的错误,但是typescript编译器没有显示这样的错误; I'm starting to believe that this issue is with the IDE. 我开始相信这个问题与IDE有关。

I have the following repository: https://github.com/danielmahadi/modular-typescript 我有以下存储库: https//github.com/danielmahadi/modular-typescript

There are 4 typescript files: 有4个打字稿文件:

  • customerModel.ts => customer model file customerModel.ts =>客户模型文件

     export class User{ constructor(public id: string, public name: string){} } 
  • converter.ts => convert json data to customer model converter.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 printer.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 webstorm 7.0.3,内部版本号:WS-133.434
  2. Mac OSX with Maverick Mac OSX与Maverick
  3. Typescript version: 0.9.5.0 打字稿版本:0.9.5.0

Typescript file watcher setting for typescript: 打字稿的打字稿文件观察器设置:

  • Typescript compiler => tsc --module commonjs --sourcemap $FileName$ 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" . 如果你用webstorm IDE打开它,你会看到在app.ts第15行,“user”总是用红线加下划线,错误为“Argument type”./customerModel'.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? 我做错了什么,或者这只是另一个网络风暴错误?

Definitely an error in webstorm. 绝对是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. 如果你在这里报告它会很感激:http: //youtrack.jetbrains.com/issues/WEB并提供一个链接,以便我们对它进行投票。

请尝试使用WebStorm 8 EAP - 该错误似乎已在那里修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 X 类型的参数不能分配给 Y 类型的参数 - Argument of type X is not assignable to parameter of type Y “X”类型的参数不能分配给“Y”类型的参数 - Argument of type 'X' is not assignable to parameter of type 'Y' TS2345:类型X的参数不能分配给类型Y的参数 - TS2345: Argument of type X is not assignable to parameter of type Y [type]类型的参数不能分配给[type]类型的参数 - Argument of type [type] is not assignable to parameter of type [type] “this”类型的参数不能分配给参数“Construct” - Argument of type 'this' not assignable to parameter 'Construct' “NextHandleFunction”类型的参数不可分配给“PathParams”类型的参数 - Argument of type 'NextHandleFunction' is not assignable to parameter of type 'PathParams' “void”类型的参数不可分配给“PathParams”类型的参数 - Argument of type 'void' is not assignable to parameter of type 'PathParams' TypeScript-类型“ {}”的参数不能分配给类型“ {}”的参数-MongoStore - TypeScript - Argument of type '{}' is not assignable to parameter of type '{}' - MongoStore “未知”类型的参数不可分配给类型参数 - Argument of type 'unknown' is not assignable to parameter of type {…} 类型的参数不能分配给 'string | 类型的参数网址' - Argument of type {…} is not assignable to parameter of type 'string | URL'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM