Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

#115: Handle tagged unions with fewer than two cases (closes #115) #116

Merged
merged 3 commits into from
Jan 31, 2020

Conversation

tpetrucciani
Copy link
Contributor

@tpetrucciani tpetrucciani commented Jan 31, 2020

Closes [#2520856](https://buildo.kaiten.io/space/[object Object]/card/2520856)

⚠️ The line above was added during the automatic migration of all github project issues to Kaiten. The old GH issue link is kept here for reference (it is now deprecated, continue follow the original issue on Kaiten).

Closes #115

  • Single-case tagged unions are now converted simply to interface declarations like

    export interface SingleCaseTaggedUnion {
      x: number,
      y: string,
      _type: 'SingleCase'
    }
    
    export const SingleCaseTaggedUnion = t.type({
      x: t.Integer,
      y: t.string,
      _type: t.literal('SingleCase')
    }, 'SingleCase')

    without the erroneous union combinator.

  • Zero-case tagged unions are just skipped in the output.

    The rationale for this is that they're not really useful right now for us because we're not generating precise types for errors (the left side of route TaskEithers) and zero-case tagged unions only make sense in the error type, not in the main route type or as field of another module.

    To move to more precise error handling, we should change this to output these types as synonyms for never, with an appropriate codec (perhaps one that always fails, probably actually anything that typechecks is fine since it won't be used).

Test Plan

  • Added 0- and 1-case tagged unions to the snapshot test
  • Tested on metarpheus output on an internal project

@tpetrucciani tpetrucciani force-pushed the 115-handle_tagged_unions_with branch from 2d22c0e to 6178e65 Compare January 31, 2020 11:45
@tpetrucciani tpetrucciani requested a review from giogonzo January 31, 2020 11:53
@nemobot nemobot added in review and removed WIP labels Jan 31, 2020
Copy link
Member

@giogonzo giogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 👏

@giogonzo giogonzo merged commit 7edbee6 into master Jan 31, 2020
@nemobot
Copy link

nemobot commented Jan 31, 2020

@giogonzo giogonzo deleted the 115-handle_tagged_unions_with branch January 31, 2020 14:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle tagged unions with fewer than two cases
3 participants