Skip to content

Union of Modddels: how to properly handle narrowed types? #8

Answered by CodingSoot
chikamichi asked this question in Q&A
Discussion options

You must be logged in to vote

No worries at all ! I appreciate your active participation and questions.

You (almost) never need to use type casting when using modddels. The package has been made to provide compile-time safety, and type casting breaks that.

Let me put your modddel here for reference. It's a union MapLayer with three case-modddels : Raster, Vector and Geojson.

@Modddel(validationSteps: [
  ValidationStep([contentValidation])
])
class MapLayer extends SimpleEntity<InvalidMapLayer, ValidMapLayer>
    with _$MapLayer {
  MapLayer._();

  factory MapLayer.raster({
    required MapLayerPosition position,
    //...
  }) {
    return _$MapLayer._createRaster(
      position: position,
      //...
    );
  }

  f…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by CodingSoot
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #7 on June 01, 2023 23:08.