Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitted type is undefined for enum #11

Open
kabukki opened this issue Jul 2, 2019 · 3 comments
Open

Emitted type is undefined for enum #11

kabukki opened this issue Jul 2, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@kabukki
Copy link

kabukki commented Jul 2, 2019

Disclaimer: I am not entirely sure I understand everything that is happening here, but I'll try my best to make sense.

I am using Typeorm while compiling Typescript with Babel 7, so I need experimentalDecorators (with @babel/plugin-proposal-decorators) and emitDecoratorMetadata (with this package).

Everything runs fine, but when I run the output code, I get the following error: Data type "undefined" in "CharacterEntity.gender" is not supported by "mysql" database., which refer to:

// CharacterEntity.ts 
@Entity('characters')
export class CharacterEntity {
	// ...

	@Column()
	gender: CharacterGender;

	// ...
}

// CharacterGender.ts
export enum CharacterGender {
	MALE = 'male',
	FEMALE = 'female'
}

When looking at the code procuded by Babel, I believe only these lines are relevant:

_dec9 = (0, _typeorm.Column)(), _dec10 = Reflect.metadata("design:type", typeof _enums.CharacterGender === "undefined" ? Object : _enums.CharacterGender)

// ...

_descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "gender", [_dec9, _dec10], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
})

// ...

 _initializerDefineProperty(this, "gender", _descriptor4, this);

So this issue is blocking me. Note that everything compiles and runs fine when using the Typescript compiler, which seems to produce:

__decorate([
    typeorm_1.Column(),
    __metadata("design:type", String)
], CharacterEntity.prototype, "gender", void 0);

I hope this is clear enough to provide enough information, it would be great if you could look into this or simply explain what I'm doing wrong :)

Thanks !

@leonardfactory
Copy link
Owner

I think here TSC is intelligent enough to convert enums into string / number when needed. I didn't test enums completely, I'll try to find a fix asap.

@leonardfactory leonardfactory added the bug Something isn't working label Jul 25, 2019
@leonardfactory
Copy link
Owner

Sorry for the extremely late answer. However, this problem arises from missing type informations (that TSC resolves thanks to its checker that is not available here in Babel. I'd try to add something like an hack for this kind of situation, like a leading comment, but the best thing for your situation now is just to rely on hand-configured varchar type for the column

@tada5hi
Copy link

tada5hi commented Feb 17, 2023

@leonardfactory any news on that ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants