Skip to content

Commit

Permalink
add TypeOf operator to Codec, Encoder, Eq and Guard, closes #462
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 4, 2020
1 parent 42a1000 commit e9a608e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@

- **Experimental**
- add `Eq` module (@gcanti)
- `Codec`
- add `TypeOf` operator (@gcanti)
- `Decoder`
- add `DecodeError` interface (@gcanti)
- `Encoder`
- add `TypeOf` operator (@gcanti)
- `Guard`
- add `TypeOf` operator (@gcanti)

# 2.2.1

Expand Down
11 changes: 11 additions & 0 deletions docs/modules/Codec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Added in v2.2.0
<h2 class="text-delta">Table of contents</h2>

- [Codec (interface)](#codec-interface)
- [TypeOf (type alias)](#typeof-type-alias)
- [URI (type alias)](#uri-type-alias)
- [URI](#uri)
- [UnknownArray](#unknownarray)
Expand Down Expand Up @@ -52,6 +53,16 @@ export interface Codec<A> extends D.Decoder<A>, E.Encoder<A> {}

Added in v2.2.0

# TypeOf (type alias)

**Signature**

```ts
export type TypeOf<C> = C extends Codec<infer A> ? A : never
```
Added in v2.2.2
# URI (type alias)
**Signature**
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/Encoder.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Added in v2.2.0
<h2 class="text-delta">Table of contents</h2>

- [Encoder (interface)](#encoder-interface)
- [TypeOf (type alias)](#typeof-type-alias)
- [URI (type alias)](#uri-type-alias)
- [URI](#uri)
- [array](#array)
Expand Down Expand Up @@ -42,6 +43,16 @@ export interface Encoder<A> {

Added in v2.2.0

# TypeOf (type alias)

**Signature**

```ts
export type TypeOf<E> = E extends Encoder<infer A> ? A : never
```
Added in v2.2.2
# URI (type alias)
**Signature**
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/Eq.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Added in v2.2.2

<h2 class="text-delta">Table of contents</h2>

- [TypeOf (type alias)](#typeof-type-alias)
- [UnknownArray](#unknownarray)
- [UnknownRecord](#unknownrecord)
- [array](#array)
Expand All @@ -30,6 +31,16 @@ Added in v2.2.2

---

# TypeOf (type alias)

**Signature**

```ts
export type TypeOf<E> = E extends Eq<infer A> ? A : never
```
Added in v2.2.2
# UnknownArray
**Signature**
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/Guard.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Added in v2.2.0
<h2 class="text-delta">Table of contents</h2>

- [Guard (interface)](#guard-interface)
- [TypeOf (type alias)](#typeof-type-alias)
- [URI (type alias)](#uri-type-alias)
- [URI](#uri)
- [UnknownArray](#unknownarray)
Expand Down Expand Up @@ -49,6 +50,16 @@ export interface Guard<A> {

Added in v2.2.0

# TypeOf (type alias)

**Signature**

```ts
export type TypeOf<G> = G extends Guard<infer A> ? A : never
```
Added in v2.2.2
# URI (type alias)
**Signature**
Expand Down
5 changes: 5 additions & 0 deletions src/Codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import { Schemable, Literal } from './Schemable'
*/
export interface Codec<A> extends D.Decoder<A>, E.Encoder<A> {}

/**
* @since 2.2.2
*/
export type TypeOf<C> = C extends Codec<infer A> ? A : never

// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/Encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface Encoder<A> {
readonly encode: (a: A) => unknown
}

/**
* @since 2.2.2
*/
export type TypeOf<E> = E extends Encoder<infer A> ? A : never

// -------------------------------------------------------------------------------------
// primitives
// -------------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/Eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import * as R from 'fp-ts/lib/Record'
import * as S from './Schemable'
import Eq = E.Eq

/**
* @since 2.2.2
*/
export type TypeOf<E> = E extends Eq<infer A> ? A : never

// -------------------------------------------------------------------------------------
// primitives
// -------------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/Guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface Guard<A> {
is: (u: unknown) => u is A
}

/**
* @since 2.2.2
*/
export type TypeOf<G> = G extends Guard<infer A> ? A : never

// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
Expand Down

0 comments on commit e9a608e

Please sign in to comment.