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

Discriminated unions with two enums are not deserialized #317

Closed
danfma opened this issue Jul 18, 2022 · 4 comments
Closed

Discriminated unions with two enums are not deserialized #317

danfma opened this issue Jul 18, 2022 · 4 comments

Comments

@danfma
Copy link

danfma commented Jul 18, 2022

If you have an enum the deepkit won't be able to deserialize it correctly.

Reproduction:

import { cast } from '@deepkit/type';

export enum StatEnginePowerUnit {
  Hp = 'hp',
}

export enum StatWeightUnit {
  Lbs = 'lbs',
  Kg = 'kg',
}

export type StatMeasurementUnit = StatEnginePowerUnit | StatWeightUnit;

console.log(cast<StatMeasurementUnit>(StatWeightUnit.Kg));

Expected behavior: it should be deserialized as 'kg'.

@marcj
Copy link
Member

marcj commented Jul 18, 2022

Can confirm this is a bug. The following is wrongly computed, likely an issue with the VM.

    enum StatEnginePowerUnit {
        Hp = 'hp',
    }

    enum StatWeightUnit {
        Lbs = 'lbs',
        Kg = 'kg',
    }

    type StatMeasurementUnit = StatEnginePowerUnit | StatWeightUnit;
    const type = typeOf<StatMeasurementUnit>(); //kind=enum, wrong

@marcj marcj closed this as completed in 291c96c Jul 18, 2022
@marcj
Copy link
Member

marcj commented Jul 18, 2022

@danfma thanks for reporting! Fixed in 291c96c.

@danfma
Copy link
Author

danfma commented Jul 19, 2022

Hey, @marcj ! I don't want to press you but, is it possible to deploy a version with the fixed bugs?

@marcj
Copy link
Member

marcj commented Jul 19, 2022

@danfma alpha-74 is released https://github.com/deepkit/deepkit-framework/releases/tag/v1.0.1-alpha.74

Char2sGu pushed a commit to Char2sGu/deepkit-framework that referenced this issue Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants