Inherited class from another module in Typescript -
i trying extend abstract class class, more convenience need have abstract class in file. unfortunately throws me runtime error struggle understand.
this works :
abstract class item{ constructor(){ console.log("i item"); } } export class folder extends item{ constructor(){ super(); } }
log :
i item
this doesn't :
module mymodule{ export abstract class item{ constructor(){ console.log("i item"); } } } export class folder extends mymodule.item{ constructor(){ super(); } }
compiles throws :
uncaught typeerror: cannot read property 'prototype' of undefined
does understand going on ?
a top-level export (export class folder
in case) in source file means typescript treat file external module, though unless specify module format when compiling typescript should have emitted error ts1148: cannot compile modules unless '--module' flag provided.
so, i'm confused how managed compile code snippets @ if you're using internal modules.
i suggest using external modules (where each .ts
file module in , of itself) , avoiding namespaces (previously known internal modules) entirely.
here's code nothing external modules:
// mymodule.ts export abstract class item { constructor() { console.log("i item"); } } // folder.ts import * mymodule './mymodule'; export class folder extends mymodule.item { constructor() { super(); }
however, if wanted stick using namespaces instead, you'd this:
namespace mymodule { export abstract class item { constructor() { console.log("i item"); } } } namespace myothermodule { export class folder extends mymodule.item { constructor() { super(); } } }
Comments
Post a Comment