Custom components

Custom components
0.0 0

#1

hi all, i have a custom class that extends cc.Component

namespace game {
    const {ccclass, property} = cc._decorator;

  @ccclass
    class CustomComponent extends cc.Component{
          ....
    }
}

this works fine and i can use the custom component with the cocos creator IDE
but when i create another component that inherits from the custom component,

namespace game {
        const {ccclass, property} = cc._decorator;

      @ccclass
        class AnotherComponent extends CustomComponent{
              ....
       }
 }

the IDE doesnt allow me to import, saying
Can not find cc.Component in the script .

it seems that the cause of the issue is the namespace
when namespaces are removed the issue is solved (but this is really not an option in the case of my project)
is there a solution or workaround for this?


#2

ok, so i found some kind of workaround
basically since i am using name spaces i need to declare a module game (for my namespace game shown above) inside an index.d.ts file
once i did this the Cocos creator was again able to work correctly
there should be a better solution for this


#3

It’s ain’t common to use a namespace, is there a good reason you need to do so? Most of the examples are done without it, maybe try eliminating that and see if that solve your issue?


#4

@jake72 you are probably right, i have a lot of legacy code from our cocos studio version of our games so i was trying to do the migration without starting re-moduling all of our classes - but it seems that refactoring our ts code to use modules instead of namespaces would be the wise, albeit difficult move