WatermelonDB: Error: Cannot use 'in' operator to search for 'initializer' in undefined (Model field decorators can only be used for simple properties)
Hi,
I was using WatermelonDB for react-native, and trying to setup the same for web. For the same model, schema definition, I am hitting this case
https://github.com/Nozbe/WatermelonDB/blob/master/src/decorators/common.js#L21
Model field decorators can only be used for simple properties - method, setter or getter
This is the field definition
...
@field('text')
// @ts-ignore
text;
...
which is not changed from native, and looks similar to other fields. But, I didn’t follow changes to the package for a month and uses latest release now.
Also, instead of above error message, it throws error because descriptor is undefined.
TypeError: Cannot use 'in' operator to search for 'initializer' in undefined
ensureDecoratorUsedProperly
node_modules/@nozbe/watermelondb/decorators/common.js:21
18 |
19 | function ensureDecoratorUsedProperly(columnName, target, key, descriptor) {
20 | (0, _invariant.default)(columnName, "Pass column name (raw field name) to the decorator - error in ".concat(target.constructor.name, ".prototype.").concat(key, " given."));
> 21 | (0, _invariant.default)('initializer' in descriptor, "Model field decorators can only be used for simple properties - method, setter or getter ".concat(target.constructor.name, ".prototype.").concat(key, " given."));
22 | (0, _invariant.default)(!(0, _is.default)(Function, descriptor.initializer), "Model field decorators must not be used on properties with a default value - error in \"".concat(target.constructor.name, ".prototype.").concat(key, "\"."));
23 | }
View compiled
thank you.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (8 by maintainers)
I found out this is happening because the code generated by TypeScript for decorators doesn’t work with the decorator code generated by this project. TypeScript doesn’t pass property descriptors when the decorator is instantiated. I think TypeScript generates older-style decorator code.
This is happening during our Jest test run using ts-jest.
I know this has been closed, but has anyone figured out a workaround for this issue?
I get the error
Cannot use 'in' operator to search for 'initializer' in undefinedwhen the@fielddecorator is used becausedescriptoris undefined.I’m using React-native with TypeScript
sorry about this! will investigate tomorrow