Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript AMD in WebStorm. Annoying "Assigned Expression type" error

I'm trying out TypeScript in JetBrains WebStorm.

I have a very simple class in "person.ts":

export class Person {
  constructor(public name:string, public age:number) {
  }
    toString() {
    return this.name + ", " + this.age;
  }
}

Then, on my app.ts I try to import it like this:

import nsp = module("person");

export class App {
    start() {
        var my_user:nsp.Person;
        my_user = new nsp.Person("Julian", 111);
        console.log( my_user.toString() );
    }
}

This seems to work. I can use tsc to compile to javascript:

tsc --module AMD .\public\script\app.ts

And I've also set up a FileWatcher for TypeScript in WebStorm. It's fine.

But I'm getting this annoying error/warning: "Assigned Expression type Person is not assignable to type exports.Person"

problem

Any ideas? Am I doing something wrong? Is this a bug in WebStorm?

Here's my project on GitHub: https://github.com/JulianG/typescript-modularization-demo/ in case you want to try it out.

like image 420
JulianG Avatar asked Apr 19 '13 11:04

JulianG


2 Answers

This bug is fixed in the next WebStorm release but in the meantime you could either ignore the error or combine the expression into a single line and see if type-inference helps:

var my_user = new nsp.Person('Julian', 111);
like image 131
Fenton Avatar answered Nov 19 '22 01:11

Fenton


Fix will be included in the next minor release also (6.0.2). Probably this was caused by WEB-7117.

like image 28
de1mar Avatar answered Nov 19 '22 02:11

de1mar