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"
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.
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);
Fix will be included in the next minor release also (6.0.2). Probably this was caused by WEB-7117.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With