{"action":"created","issue":{"url":"https://api.github.com/repos/szokodiakos/typegoose/issues/211","repository_url":"https://api.github.com/repos/szokodiakos/typegoose","labels_url":"https://api.github.com/repos/szokodiakos/typegoose/issues/211/labels{/name}","comments_url":"https://api.github.com/repos/szokodiakos/typegoose/issues/211/comments","events_url":"https://api.github.com/repos/szokodiakos/typegoose/issues/211/events","html_url":"https://github.com/szokodiakos/typegoose/issues/211","id":372619381,"node_id":"MDU6SXNzdWUzNzI2MTkzODE=","number":211,"title":"Two way Ref causes compile error","user":{"login":"FSM1","id":12774278,"node_id":"MDQ6VXNlcjEyNzc0Mjc4","avatar_url":"https://avatars0.githubusercontent.com/u/12774278?v=4","gravatar_id":"","url":"https://api.github.com/users/FSM1","html_url":"https://github.com/FSM1","followers_url":"https://api.github.com/users/FSM1/followers","following_url":"https://api.github.com/users/FSM1/following{/other_user}","gists_url":"https://api.github.com/users/FSM1/gists{/gist_id}","starred_url":"https://api.github.com/users/FSM1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FSM1/subscriptions","organizations_url":"https://api.github.com/users/FSM1/orgs","repos_url":"https://api.github.com/users/FSM1/repos","events_url":"https://api.github.com/users/FSM1/events{/privacy}","received_events_url":"https://api.github.com/users/FSM1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-22T17:33:25Z","updated_at":"2018-11-13T13:36:50Z","closed_at":null,"author_association":"NONE","body":"model classes both Ref each other: eg.\r\n\r\n```\r\n// User.ts\r\nimport { Pet } from './Pet';\r\n\r\nexport class User extends Typegoose {\r\n    @IsEmail()\r\n    @prop({required: true, unique: true, sparse: true })\r\n    public email: string;\r\n\r\n    @prop({required: true})\r\n    public password: string;\r\n\r\n    // more code here\r\n\r\n    //source of problems\r\n    @arrayProp({ itemsRef: Pet, default: [], required: false })\r\n    public pets?: Array<Ref<Pet>>;\r\n\r\n}\r\n\r\n// Pet.ts\r\n\r\nimport { User } from './User';\r\n\r\nexport class Pet extends Typegoose {\r\n    @prop({required: true})\r\n    public name: string;\r\n\r\n    @prop({ref: User, required: true})\r\n    public owner: Ref<User>;\r\n}\r\n\r\n```\r\nthe app fails to start and throws the following stack trace:\r\n\r\n```\r\n\r\nC:\\Users\\myank\\Code\\LinumLabs\\molecule-sandbox\\ApiServer\\node_modules\\typegoose\\lib\\prop.js:67\r\n    const instance = new Type();\r\n                     ^\r\nTypeError: Type is not a constructor\r\n    at baseProp (\\node_modules\\typegoose\\lib\\prop.js:67:22)\r\n    at \\node_modules\\typegoose\\lib\\prop.js:105:5\r\n    at DecorateProperty (\\node_modules\\reflect-metadata\\Reflect.ts:1214:35)\r\n    at Object.decorate (\\node_modules\\reflect-metadata\\Reflect.ts:737:24)\r\n    at Object.__decorate (\\node_modules\\tslib\\tslib.js:89:96)\r\n    at Object.<anonymous> (\\models\\User.ts:32:5)\r\n    at Module._compile (module.js:653:30)\r\n    at Module.m._compile (\\node_modules\\ts-node\\src\\index.ts:439:23)\r\n    at Module._extensions.js (module.js:664:10)\r\n    at Object.require.extensions.(anonymous function) [as .ts] (\\node_modules\\ts-node\\src\\index.ts:442:12)\r\n    at Module.load (module.js:566:32)\r\n    at tryModuleLoad (module.js:506:12)\r\n    at Function.Module._load (module.js:498:3)\r\n    at Module.require (module.js:597:17)\r\n    at require (internal/module.js:11:18)\r\n    at Object.<anonymous> (models\\Pet.ts:3:1)\r\n\r\n```\r\n\r\nIf I remove the User.pets arrayProp then the app compiles again."},"comment":{"url":"https://api.github.com/repos/szokodiakos/typegoose/issues/comments/438268034","html_url":"https://github.com/szokodiakos/typegoose/issues/211#issuecomment-438268034","issue_url":"https://api.github.com/repos/szokodiakos/typegoose/issues/211","id":438268034,"node_id":"MDEyOklzc3VlQ29tbWVudDQzODI2ODAzNA==","user":{"login":"FSM1","id":12774278,"node_id":"MDQ6VXNlcjEyNzc0Mjc4","avatar_url":"https://avatars0.githubusercontent.com/u/12774278?v=4","gravatar_id":"","url":"https://api.github.com/users/FSM1","html_url":"https://github.com/FSM1","followers_url":"https://api.github.com/users/FSM1/followers","following_url":"https://api.github.com/users/FSM1/following{/other_user}","gists_url":"https://api.github.com/users/FSM1/gists{/gist_id}","starred_url":"https://api.github.com/users/FSM1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FSM1/subscriptions","organizations_url":"https://api.github.com/users/FSM1/orgs","repos_url":"https://api.github.com/users/FSM1/repos","events_url":"https://api.github.com/users/FSM1/events{/privacy}","received_events_url":"https://api.github.com/users/FSM1/received_events","type":"User","site_admin":false},"created_at":"2018-11-13T13:36:50Z","updated_at":"2018-11-13T13:36:50Z","author_association":"NONE","body":"this seems to happen whenever there are cyclic dependencies in the models, as evidenced by #116, #143 "}}
{"actor":{"display_login":"FSM1"}}