{"action":"created","issue":{"url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/558","repository_url":"https://api.github.com/repos/mobxjs/mobx-state-tree","labels_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/558/labels{/name}","comments_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/558/comments","events_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/558/events","html_url":"https://github.com/mobxjs/mobx-state-tree/issues/558","id":280473210,"number":558,"title":"[help-needed] Trying to come up with a custom-type reference","user":{"login":"devdoomari","id":6072026,"avatar_url":"https://avatars3.githubusercontent.com/u/6072026?v=4","gravatar_id":"","url":"https://api.github.com/users/devdoomari","html_url":"https://github.com/devdoomari","followers_url":"https://api.github.com/users/devdoomari/followers","following_url":"https://api.github.com/users/devdoomari/following{/other_user}","gists_url":"https://api.github.com/users/devdoomari/gists{/gist_id}","starred_url":"https://api.github.com/users/devdoomari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devdoomari/subscriptions","organizations_url":"https://api.github.com/users/devdoomari/orgs","repos_url":"https://api.github.com/users/devdoomari/repos","events_url":"https://api.github.com/users/devdoomari/events{/privacy}","received_events_url":"https://api.github.com/users/devdoomari/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2017-12-08T12:24:32Z","updated_at":"2018-03-14T14:51:47Z","closed_at":"2018-03-14T14:51:47Z","author_association":"NONE","body":"I'm trying to create a Decimal.js MST primitive, but the following code compiles but fails at runtime:\r\n\r\n```typescript\r\nimport {\r\n  IType,\r\n  CoreType, // I've added a custom MST repo for a quick attempt\r\n  TypeFlags,\r\n} from 'mobx-state-tree';\r\nimport Decimal from 'decimal.js';\r\n\r\nexport const DecimalPrimitive: IType<string | number, Decimal> =\r\n  new CoreType<string | number, Decimal>(\r\n    'Decimal',\r\n    TypeFlags.Reference,\r\n    (v: any) => (\r\n      typeof v === \"string\"\r\n      || typeof v === \"number\"\r\n      || v instanceof Decimal\r\n    ),\r\n    (v: string | Decimal) => (v instanceof Decimal? v : new Decimal(v)),\r\n  );\r\n```\r\n\r\nHere's the model definition part:\r\n```typescript\r\nexport const Wallet = types.model<WalletType>('Wallet', {\r\n  balance: types.reference(DecimalPrimitive),\r\n})\r\n```\r\nAnd this is what I get when I try to access someWallet.balance in a reactJS component:\r\n\r\n```\r\nrender() {\r\n   return (\r\n     <div> { wallet.balance.toNumber() } </div>\r\n   );\r\n}\r\n\r\n// --> Failed to resolve reference of type Decimal: '50' (in: /balance)\r\n```\r\n\r\nAny ideas on how I should proceed?\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/comments/373049134","html_url":"https://github.com/mobxjs/mobx-state-tree/issues/558#issuecomment-373049134","issue_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/558","id":373049134,"user":{"login":"robinfehr","id":6340698,"avatar_url":"https://avatars0.githubusercontent.com/u/6340698?v=4","gravatar_id":"","url":"https://api.github.com/users/robinfehr","html_url":"https://github.com/robinfehr","followers_url":"https://api.github.com/users/robinfehr/followers","following_url":"https://api.github.com/users/robinfehr/following{/other_user}","gists_url":"https://api.github.com/users/robinfehr/gists{/gist_id}","starred_url":"https://api.github.com/users/robinfehr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robinfehr/subscriptions","organizations_url":"https://api.github.com/users/robinfehr/orgs","repos_url":"https://api.github.com/users/robinfehr/repos","events_url":"https://api.github.com/users/robinfehr/events{/privacy}","received_events_url":"https://api.github.com/users/robinfehr/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T14:51:47Z","updated_at":"2018-03-14T14:51:47Z","author_association":"CONTRIBUTOR","body":"custom types merged."}}
{"actor":{"display_login":"robinfehr"}}