Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 2.8 — initial support & updates #14

Merged
merged 7 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ yarn add type-zoo

## API

### `Diff<T extends string, U extends string>`

Remove the variants of the second union of string literals from the first.

See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458

---

### `NoInfer<T>`

Use to prevent a usage of type `T` from being inferred in other generics.

Example:

```ts
declare function assertEqual<T>(actual: T, expected: NoInfer<T>): boolean;
```
Expand All @@ -38,33 +33,19 @@ See: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-322267089

---

### `NonNullable<T>`

`T` without the possibility of `undefined` or `null`.

See: https://github.com/Microsoft/TypeScript/issues/15012#issuecomment-346499713

---

### `Omit<T, K extends keyof T>`

Drop keys `K` from `T`.

See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458

---

### `Overlap<T extends string, U extends string>`

Find the overlapping variants between two string unions.
See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046

---

### `Overwrite<T, U>`

Like `T & U`, but where there are overlapping properties using the type from `U` only.

See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458
See: https://github.com/pelotom/type-zoo/pull/14#discussion_r183527882

---

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"author": "Tom Crockett",
"license": "MIT",
"devDependencies": {
"dtslint": "^0.2.0",
"typescript": "^2.6.2"
"dtslint": "^0.3.0",
"typescript": "^2.8.1"
},
"scripts": {
"test": "dtslint types"
Expand Down
6 changes: 0 additions & 6 deletions types/diff.ts

This file was deleted.

37 changes: 7 additions & 30 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
// TypeScript Version: 2.6

/**
* Remove the variants of the second union of string literals from
* the first.
*
* @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458
*/
export type Diff<T extends string, U extends string> = (
& { [P in T]: P }
& { [P in U]: never }
& { [x: string]: never }
)[T];
// TypeScript Version: 2.8

/**
* Drop keys `K` from `T`.
*
* @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458
*/
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

/**
* Find the overlapping variants between two string unions.
* @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046
*/
export type Overlap<T extends string, U extends string> = Diff<T, Diff<T, U>>;
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

/**
* Like `T & U`, but where there are overlapping properties using the
* type from U only.
*
* @see https://github.com/pelotom/type-zoo/issues/2
* @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458
* @see Old: https://github.com/pelotom/type-zoo/issues/2
* @see Old: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458
* @see New: https://github.com/pelotom/type-zoo/pull/14#discussion_r183527882
*/
export type Overwrite<T, U> = Omit<T, Overlap<keyof T, keyof U>> & U;
export type Overwrite<T, U> = Omit<T, keyof T & keyof U> & U;

/**
* Use to prevent a usage of type `T` from being inferred in other generics.
Expand All @@ -48,13 +32,6 @@ export type Overwrite<T, U> = Omit<T, Overlap<keyof T, keyof U>> & U;
*/
export type NoInfer<T> = T & { [K in keyof T]: T[K] };

/**
* `T` without the possibility of `undefined` or `null`.
*
* @see https://github.com/Microsoft/TypeScript/issues/15012#issuecomment-346499713
*/
export type NonNullable<T> = T & {};

/**
* Forgets contextual knowledge of partiality of keys.
*/
Expand Down
5 changes: 0 additions & 5 deletions types/non-nullable.ts

This file was deleted.

6 changes: 0 additions & 6 deletions types/overlap.ts

This file was deleted.

20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ [email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

definitelytyped-header-parser@Microsoft/definitelytyped-header-parser#production:
"definitelytyped-header-parser@github:Microsoft/definitelytyped-header-parser#production":
version "0.0.0"
resolved "https://codeload.github.com/Microsoft/definitelytyped-header-parser/tar.gz/210b44cf9e7e5b9783a41df4f664695ade5325b1"
resolved "https://codeload.github.com/Microsoft/definitelytyped-header-parser/tar.gz/f074e863231ef0d79a31c0a9edaf1b82c98469ef"
dependencies:
"@types/parsimmon" "^1.3.0"
parsimmon "^1.2.0"
Expand All @@ -100,14 +100,14 @@ diff@^3.2.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"

dtslint@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/dtslint/-/dtslint-0.2.0.tgz#7723be0d974ad133ff1e5cdb84728669ca66c51e"
dtslint@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/dtslint/-/dtslint-0.3.0.tgz#918e664a6f7e1f54ba22088daa2bc6e64a6001c1"
dependencies:
definitelytyped-header-parser Microsoft/definitelytyped-header-parser#production
fs-promise "^2.0.0"
strip-json-comments "^2.0.1"
tslint "^5.4.2"
tslint "^5.9.1"
typescript next

escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
Expand Down Expand Up @@ -281,7 +281,7 @@ tslib@^1.8.0, tslib@^1.8.1:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"

tslint@^5.4.2:
tslint@^5.9.1:
version "5.9.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.9.1.tgz#1255f87a3ff57eb0b0e1f0e610a8b4748046c9ae"
dependencies:
Expand All @@ -304,9 +304,9 @@ tsutils@^2.12.1:
dependencies:
tslib "^1.8.1"

typescript@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
typescript@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"

typescript@next:
version "2.8.0-dev.20180127"
Expand Down