plainfp - v0.1.0
    Preparing search index...

    Function tag

    • Build a constructor for tagged values sharing a fixed _tag. The returned function stamps the tag over any user-supplied _tag, keeping discriminants trustworthy for hasTag and switch narrowing.

      Type Parameters

      • Tag extends string

      Parameters

      Returns <Data extends object = object>(data?: Data) => Tagged<Tag, Data>

      const loading = tag("Loading")
      const loaded = tag("Loaded")
      type State =
      | ReturnType<typeof loading>
      | ReturnType<typeof loaded<{ users: User[] }>>

      const s: State = loaded({ users: [] })
      // { _tag: "Loaded", users: [] }