{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/10579","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/10579/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/10579/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/10579/events","html_url":"https://github.com/sequelize/sequelize/issues/10579","id":423029718,"node_id":"MDU6SXNzdWU0MjMwMjk3MTg=","number":10579,"title":"Sequelize with TypeScript - class fields undefined","user":{"login":"petrovi4","id":178891,"node_id":"MDQ6VXNlcjE3ODg5MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/178891?v=4","gravatar_id":"","url":"https://api.github.com/users/petrovi4","html_url":"https://github.com/petrovi4","followers_url":"https://api.github.com/users/petrovi4/followers","following_url":"https://api.github.com/users/petrovi4/following{/other_user}","gists_url":"https://api.github.com/users/petrovi4/gists{/gist_id}","starred_url":"https://api.github.com/users/petrovi4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrovi4/subscriptions","organizations_url":"https://api.github.com/users/petrovi4/orgs","repos_url":"https://api.github.com/users/petrovi4/repos","events_url":"https://api.github.com/users/petrovi4/events{/privacy}","received_events_url":"https://api.github.com/users/petrovi4/received_events","type":"User","site_admin":false},"labels":[{"id":447474598,"node_id":"MDU6TGFiZWw0NDc0NzQ1OTg=","url":"https://api.github.com/repos/sequelize/sequelize/labels/needs%20more%20info","name":"needs more info","color":"fef2c0","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2019-03-20T01:54:16Z","updated_at":"2019-04-24T01:21:07Z","closed_at":"2019-03-22T21:47:18Z","author_association":"NONE","body":"## What are you doing?\r\nI'am using Babel for code compilation + TypeScript for type-checking.\r\nTwo scenarios:\r\n\r\n1. Using define, which is \"really wouldn't recommend this\" (according types/test/define.ts comments)\r\n```js\r\ninterface User extends Model {\r\n\tid: number;\r\n\tlogin: string;\r\n}\r\n\r\ntype UserModel = {\r\n\tnew (): User;\r\n} & typeof Model;\r\n\r\nconst User = sequelize.define(\r\n\t'User',\r\n\t{ login: DataTypes.STRING\t},\r\n\t{ tableName: 'user' }\r\n) as UserModel;\r\n```\r\n\r\n2. Using new approach (based on code, found in the types/models/User.ts)\r\n\r\n```js\r\nexport class User extends Model {\r\n\tpublic id: number;\r\n\tpublic login: string;\r\n}\r\n\r\nUser = User.init(\r\n\t{ login: DataTypes.STRING },\r\n\t{\tsequelize, tableName: 'user' }\r\n);\r\n```\r\nIn DB (Postgres) I have one row with login 'admin'.\r\n\r\nFor the test, I use this function.\r\n\r\n```js\r\nasync function test() {\r\n\tconst user = (await User.findOne()) as User;\r\n\tconsole.log('login', user.login, user.get('login'));\r\n}\r\ntest();\r\n```\r\n\r\n## What do you expect to happen?\r\nIt is logical that in both scenarios I should get \r\n\r\n> login admin admin\r\n\r\n\r\n## What is actually happening?\r\nHowever, if in \"modern\", second approach I see \r\n\r\n> login undefined admin\r\n\r\n\r\nAnd if I print console.log(user) I see\r\n```js\r\nuser1 User {\r\n  dataValues:\r\n   { id: 1,\r\n     login: 'admin',\r\n     createdAt: 2019-03-18T23:00:33.516Z,\r\n     updatedAt: 2019-03-18T23:00:33.516Z },\r\n  _previousDataValues:\r\n   { id: 1,\r\n     login: 'admin',\r\n     createdAt: 2019-03-18T23:00:33.516Z,\r\n     updatedAt: 2019-03-18T23:00:33.516Z },\r\n  _changed: {},\r\n  _modelOptions:\r\n   { timestamps: true,\r\n     validate: {},\r\n     freezeTableName: false,\r\n     underscored: false,\r\n     paranoid: false,\r\n     rejectOnEmpty: false,\r\n     whereCollection: null,\r\n     schema: null,\r\n     schemaDelimiter: '',\r\n     defaultScope: {},\r\n     scopes: {},\r\n     indexes: [],\r\n     name: { plural: 'Users', singular: 'User' },\r\n     omitNull: false,\r\n     sequelize:\r\n      Sequelize {\r\n        options: [Object],\r\n        config: [Object],\r\n        dialect: [PostgresDialect],\r\n        queryInterface: [QueryInterface],\r\n        models: [Object],\r\n        modelManager: [ModelManager],\r\n        connectionManager: [ConnectionManager],\r\n        importCache: {},\r\n        test: [Object] },\r\n     tableName: 'user',\r\n     hooks: {} },\r\n  _options:\r\n   { isNewRecord: false,\r\n     _schema: null,\r\n     _schemaDelimiter: '',\r\n     raw: true,\r\n     attributes: [ 'id', 'login', 'createdAt', 'updatedAt' ] },\r\n  isNewRecord: false,\r\n  id: undefined,\r\n  login: undefined }\r\n```\r\n\r\n\r\nDialect: postgres\r\n\"sequelize\": \"^5.1.0\",\r\n\r\nupd:\r\nJust tested with ts-node - everything works as it should. \r\nHere is my .babelrc\r\n\r\n```js\r\n{\r\n\t\"sourceMaps\": \"inline\",\r\n\t\"retainLines\": true,\r\n\r\n\t\"presets\": [\r\n\t\t[\r\n\t\t\t\"@babel/preset-env\",\r\n\t\t\t{\r\n\t\t\t\t\"targets\": {\r\n\t\t\t\t\t\"node\": true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t],\r\n\t\t\"@babel/preset-typescript\"\r\n\t],\r\n\t\"plugins\": [\r\n\t\t\"@babel/plugin-proposal-optional-chaining\",\r\n\t\t\"@babel/plugin-proposal-object-rest-spread\",\r\n\t\t\"@babel/proposal-class-properties\"\r\n\t]\r\n}\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/486030911","html_url":"https://github.com/sequelize/sequelize/issues/10579#issuecomment-486030911","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/10579","id":486030911,"node_id":"MDEyOklzc3VlQ29tbWVudDQ4NjAzMDkxMQ==","user":{"login":"DanielRamosAcosta","id":11427028,"node_id":"MDQ6VXNlcjExNDI3MDI4","avatar_url":"https://avatars0.githubusercontent.com/u/11427028?v=4","gravatar_id":"","url":"https://api.github.com/users/DanielRamosAcosta","html_url":"https://github.com/DanielRamosAcosta","followers_url":"https://api.github.com/users/DanielRamosAcosta/followers","following_url":"https://api.github.com/users/DanielRamosAcosta/following{/other_user}","gists_url":"https://api.github.com/users/DanielRamosAcosta/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRamosAcosta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRamosAcosta/subscriptions","organizations_url":"https://api.github.com/users/DanielRamosAcosta/orgs","repos_url":"https://api.github.com/users/DanielRamosAcosta/repos","events_url":"https://api.github.com/users/DanielRamosAcosta/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRamosAcosta/received_events","type":"User","site_admin":false},"created_at":"2019-04-24T01:21:07Z","updated_at":"2019-04-24T01:21:07Z","author_association":"NONE","body":"The only other solution I see, is remove the `babel-plugin-proposal-class-properties` and upgrade to node 12 which supports class properties natively 😕 "}}
{"actor":{"display_login":"DanielRamosAcosta"}}