Having trouble with a Union

    var zevConfig: ZevConfig = match(zevContract.contractConfig.contractConfigDetails) {
        is ZevConfig -> optionalOf(zevContract.contractConfig.contractConfigDetails.ZevConfig)
        is VewaConfig -> optionalOf<ZevConfig>()
    }.getOrFail();

Is giving me

NPL: Error: E0009: Method 'ZevConfig' does not exist on type '/contract/ContractConfigDetails'

How do I get the value of the union?

Hi Sandy,

It’s hard to help you out with only a snippet of the code.

Once potential source of error is the capital letter at the start of the ZevConfig variable on the type contractConfigDetails.

... -> optionalOf(zevContract.contractConfig.contractConfigDetails.ZevConfig)

It is good practice to name variables following the lower camel case.

Please share more of the code otherwise :slight_smile:

Best, Jean

Ok it looks like

    var zevConfig: ZevConfig = match(zevContract.contractConfig.contractConfigDetails) {
        is ZevConfig -> optionalOf(zevContract.contractConfig.contractConfigDetails)
        is VewaConfig -> optionalOf<ZevConfig>()
    }.getOrFail();

Works as expected, but the IDE doesn’t like it “unresolved reference getOrFail” the version in the Plugin is 2025.1.9, the code

Hi Sandy,

In your second example, you’re mixing return types between the ZevConfig and VewaConfig matches. Once an optional of VewaConfig and once an optional of ContractConfigDetails. It will thus not have any getOrFail