This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac156ef
commit 41ddfb7
Showing
8 changed files
with
351 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@effect/data": patch | ||
--- | ||
|
||
added Types module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
--- | ||
title: Types.ts | ||
nav_order: 47 | ||
parent: Modules | ||
--- | ||
|
||
## Types overview | ||
|
||
A collection of types that are commonly used types. | ||
|
||
Added in v1.0.0 | ||
|
||
--- | ||
|
||
<h2 class="text-delta">Table of contents</h2> | ||
|
||
- [models](#models) | ||
- [Equals (type alias)](#equals-type-alias) | ||
- [MergeLeft (type alias)](#mergeleft-type-alias) | ||
- [MergeRight (type alias)](#mergeright-type-alias) | ||
- [types](#types) | ||
- [ExcludeTag (type alias)](#excludetag-type-alias) | ||
- [ExtractTag (type alias)](#extracttag-type-alias) | ||
- [Simplify (type alias)](#simplify-type-alias) | ||
- [Tags (type alias)](#tags-type-alias) | ||
- [UnionToIntersection (type alias)](#uniontointersection-type-alias) | ||
|
||
--- | ||
|
||
# models | ||
|
||
## Equals (type alias) | ||
|
||
Determines if two types are equal. | ||
|
||
**Signature** | ||
|
||
```ts | ||
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
|
||
type Res1 = Types.Equals<{ a: number }, { a: number }> // true | ||
type Res2 = Types.Equals<{ a: number }, { b: number }> // false | ||
``` | ||
Added in v1.0.0 | ||
## MergeLeft (type alias) | ||
Merges two object where the keys of the left object take precedence in the case of a conflict. | ||
**Signature** | ||
```ts | ||
export type MergeLeft<K, H> = Simplify<{ | ||
[k in keyof K | keyof H]: k extends keyof K ? K[k] : k extends keyof H ? H[k] : never | ||
}> | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
type MergeLeft = Types.MergeLeft<{ a: number; b: number }, { a: string }> // { a: number; b: number; } | ||
``` | ||
Added in v1.0.0 | ||
## MergeRight (type alias) | ||
Merges two object where the keys of the right object take precedence in the case of a conflict. | ||
**Signature** | ||
```ts | ||
export type MergeRight<K, H> = Simplify<{ | ||
[k in keyof K | keyof H]: k extends keyof H ? H[k] : k extends keyof K ? K[k] : never | ||
}> | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
type MergeRight = Types.MergeRight<{ a: number; b: number }, { a: string }> // { a: string; b: number; } | ||
``` | ||
Added in v1.0.0 | ||
# types | ||
## ExcludeTag (type alias) | ||
Excludes the tagged object from the type. | ||
**Signature** | ||
```ts | ||
export type ExcludeTag<E, K extends Tags<E>> = Exclude<E, { _tag: K }> | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
|
||
type Res = Types.ExcludeTag<string | { _tag: 'a' } | { _tag: 'b' }, 'a'> // string | { _tag: "b" } | ||
``` | ||
Added in v1.0.0 | ||
## ExtractTag (type alias) | ||
Extracts the type of the given tag. | ||
**Signature** | ||
```ts | ||
export type ExtractTag<E, K extends Tags<E>> = Extract<E, { _tag: K }> | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
|
||
type Res = Types.ExtractTag<{ _tag: 'a'; a: number } | { _tag: 'b'; b: number }, 'b'> // { _tag: "b", b: number } | ||
``` | ||
Added in v1.0.0 | ||
## Simplify (type alias) | ||
Simplifies the type signature of a type. | ||
**Signature** | ||
```ts | ||
export type Simplify<A> = { | ||
[K in keyof A]: A[K] | ||
} extends infer B | ||
? B | ||
: never | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
|
||
type Res = Types.Simplify<{ a: number } & { b: number }> // { a: number; b: number; } | ||
``` | ||
Added in v1.0.0 | ||
## Tags (type alias) | ||
Returns the tags in a type. | ||
**Signature** | ||
```ts | ||
export type Tags<E> = E extends { _tag: string } ? E['_tag'] : never | ||
``` | ||
**Example** | ||
```ts | ||
import * as Types from '@effect/data/Types' | ||
|
||
type Res = Types.Tags<string | { _tag: 'a' } | { _tag: 'b' }> // "a" | "b" | ||
``` | ||
Added in v1.0.0 | ||
## UnionToIntersection (type alias) | ||
A utility type that transforms a union type `T` into an intersection type. | ||
**Signature** | ||
```ts | ||
export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never | ||
``` | ||
Added in v1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as Types from '@effect/data/Types' | ||
|
||
// $ExpectType { a: string; } & { b: number; } | ||
type UnionToIntersection = Types.UnionToIntersection<{ a: string } | { b: number }> | ||
|
||
// $ExpectType "a" | "b" | ||
type Tags = Types.Tags<string | { _tag: "a" } | { _tag: "b" }> & unknown | ||
|
||
// $ExpectType string | { _tag: "b"; } | ||
type ExcludeTag = Types.ExcludeTag<string | { _tag: "a" } | { _tag: "b" }, "a"> & unknown | ||
|
||
// $ExpectType { _tag: "b"; b: number; } | ||
type ExtractTag = Types.ExtractTag<string | { _tag: "a", a: number } | { _tag: "b", b: number }, "b"> & unknown | ||
|
||
// $ExpectType { a: number; b: number; } | ||
type Simplify = Types.Simplify<object & { a: number } & { b: number }> | ||
|
||
// $ExpectType true | ||
type Equals1 = Types.Equals<{ a: number }, { a: number }> | ||
|
||
// $ExpectType false | ||
type Equals2 = Types.Equals<{ a: number }, { b: number }> | ||
|
||
// $ExpectType { a: number; b: number; } | ||
type MergeLeft = Types.MergeLeft<{ a: number, b: number; }, { a: string }> | ||
|
||
// $ExpectType { a: string; b: number; } | ||
type MergeRight = Types.MergeRight<{ a: number, b: number; }, { a: string }> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.