FromElm variantAdd a variant to our FromElm
We now have an inexhaustive case expression in our fromElm Encoder.
To handle the additional variant in our Encoder, the steps are:
vAttemptLogIn (v is short for variant). This parameter will be an encoder that we can use in our case expression.vAttemptLogIn for the AttemptLogIn record -> clause in our case expression|> TsEncode.variantTagged to the pipeline (this is the Encoder we get as the vAttemptLogIn parameter).All the code together looks like:
fromElm : Encoder FromElm
fromElm =
TsEncode.union
(\vAlert vAttemptLogIn value ->
case value of
Alert string ->
vAlert string
AttemptLogIn record ->
vAttemptLogIn record
)
|> TsEncode.variantTagged "alert"
(TsEncode.object
[ required "message" (\value -> value.message) TsEncode.string
, required "logKind" (\value -> value.kind) Log.encoder
]
)
|> TsEncode.variantTagged "attemptLogIn"
(TsEncode.object
[ required "username" (\value -> value.username) TsEncode.string
]
)
|> TsEncode.buildUnion
ellie-app fQY3tzjQDRRa1The fromElm value we receive in interopFromElm.subscribe is a TypeScript Discriminated Union.
switch-exhaustiveness-check.eslint configuration in the elm-ts-interop-starter repotsc) on your build server. We don't want our code to go to production if there are any problems here, that way we get more Elm-like guarantees in our TypeScript code like inexhaustive checks.