question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.setDataValue() does not type-check correctly inside an attribute setter

See original GitHub issue

I want use ‘setDataValue’, ‘getDataValue’ in typescript,so I write in this way.

this.setDataValue('points', JSON.stringify(val)); // error

but it’s error, so I write like this.

const Model = app.model.define(
    'area',
    {
      areaId: {
        type: INTEGER,
        primaryKey: true,
        allowNull: false,
        autoIncrement: true,
      },
      name: { type: STRING(32), allowNull: false },
      points: {
        type: TEXT,
        set(val) {
          // this.setDataValue('points', JSON.stringify(val)); //error.
          Model.prototype.setDataValue.bind(this)(             //correct
            'points',
            JSON.stringify(val),
          );
        },
        get() {
          return JSON.parse(Model.prototype.getDataValue.bind(this)('points'));
        },
      },
    },
    {
      timestamps: false,
    },
  ) as IArea;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
papbcommented, Aug 3, 2019

@rolandleth Thanks! You too!

1reaction
rolandlethcommented, Aug 3, 2019

Oh, I totally missed OP’s bind(this) 😞 I thought it behaves differently because I’m using classes, which is why I also thought about a different issue. Thank you for the call(this... suggestion!

Have a great Saturday, @papb!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize type changing getter/setter with Typescript
I got a red line under the extras saying: Type '{ [key: string]: any; }' is not assignable to type 'string'.
Read more >
Getters, Setters & Virtuals - Sequelize
Sequelize allows you to define custom getters and setters for the attributes of your models.
Read more >
Changelog - Unified Automation GmbH
It was not set correctly for AbsolutDeadband. - In UaMonitoredItem, skip the deadband check if sdkMustHandleAbsoluteDeadband is set to false.
Read more >
The @property Decorator in Python: Its Use Cases ...
How you can use @property to define getters, setters, and deleters. ... This instance attribute is public because its name doesn't have a ......
Read more >
qooxdoo Documentation
The qooxdoo developer does not even have to know ... Removal of debug statements within the application code before deployment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found