admin管理员组文章数量:1208155
I've searched and the answers I found didn't help me.
I created a class in Typescript and wanted to import it to another Typescript-File via
import '../EventDTO';
Than I looked into the converted file (main.js) where all my typescript files are converted to. In there, there's also the class which I've written, but when I want to use it in my file like:
eventList[i] = new EventDTO(data[i].id);
I get this Error in my browser:
Uncaught ReferenceError: EventDTO is not defined
EventDTO class:
class EventDTO{
id: number;
constructor(_id: number){
this.id = _id;
}
getId(){
return this.id;
}
So, how can I do this correctly?
I've searched and the answers I found didn't help me.
I created a class in Typescript and wanted to import it to another Typescript-File via
import '../EventDTO';
Than I looked into the converted file (main.js) where all my typescript files are converted to. In there, there's also the class which I've written, but when I want to use it in my file like:
eventList[i] = new EventDTO(data[i].id);
I get this Error in my browser:
Uncaught ReferenceError: EventDTO is not defined
EventDTO class:
class EventDTO{
id: number;
constructor(_id: number){
this.id = _id;
}
getId(){
return this.id;
}
So, how can I do this correctly?
Share Improve this question asked Feb 1, 2017 at 10:28 Markus G.Markus G. 1,7183 gold badges27 silver badges53 bronze badges2 Answers
Reset to default 19You would need to add export
keyword
export class EventDTO{
id: number;
constructor(_id: number){
this.id = _id;
}
getId(){
return this.id;
}
Just export the class in EventDTO.ts:
export class EventDTO { ... }
本文标签: javascriptTypeScriptclass is not definedStack Overflow
版权声明:本文标题:javascript - Typescript, class is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738747367a2110197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论