From dd32b5c75774fb859fa59704e724233bd6c95243 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Tue, 3 Apr 2018 00:26:40 -0700 Subject: [PATCH 1/7] =?UTF-8?q?TypeScript=202.8=20=E2=80=94=20initial=20su?= =?UTF-8?q?pport=20&=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++--------------- package.json | 2 +- types/index.d.ts | 21 ++++++++++++--------- yarn.lock | 6 +++--- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index e0cbdb8..75ce3b1 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,6 @@ yarn add type-zoo ## API -### `Diff` - -Remove the variants of the second union of string literals from the first. - -See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 - --- ### `NoInfer` @@ -25,6 +19,7 @@ See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 Use to prevent a usage of type `T` from being inferred in other generics. Example: + ```ts declare function assertEqual(actual: T, expected: NoInfer): boolean; ``` @@ -38,19 +33,11 @@ See: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-322267089 --- -### `NonNullable` - -`T` without the possibility of `undefined` or `null`. - -See: https://github.com/Microsoft/TypeScript/issues/15012#issuecomment-346499713 - ---- - ### `Omit` Drop keys `K` from `T`. -See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 +See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 --- diff --git a/package.json b/package.json index 567b25c..81b390c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "MIT", "devDependencies": { "dtslint": "^0.2.0", - "typescript": "^2.6.2" + "typescript": "^2.8.1" }, "scripts": { "test": "dtslint types" diff --git a/types/index.d.ts b/types/index.d.ts index b40bb45..cbc4b83 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,10 +1,12 @@ -// TypeScript Version: 2.6 +// TypeScript Version: 2.8 /** * Remove the variants of the second union of string literals from * the first. * - * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 + * TypeScript Documentation suggests that as of 2.8 you should use the built-in "Exclude" instead. + * + * @see https://github.com/Microsoft/TypeScript-Handbook/blame/master/pages/release%20notes/TypeScript%202.8.md#L245 */ export type Diff = ( & { [P in T]: P } @@ -15,9 +17,9 @@ export type Diff = ( /** * Drop keys `K` from `T`. * - * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 + * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 */ -export type Omit = Pick>; +export type Omit = Pick>; /** * Find the overlapping variants between two string unions. @@ -29,9 +31,11 @@ export type Overlap = Diff>; * type from U only. * * @see https://github.com/pelotom/type-zoo/issues/2 - * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 + * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377692897 */ -export type Overwrite = Omit> & U; +export type Overwrite = { + [P in Exclude]: T[P] +} & U; /** * Use to prevent a usage of type `T` from being inferred in other generics. @@ -49,9 +53,8 @@ export type Overwrite = Omit> & U; export type NoInfer = 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 + * Deprecated: available in TypeScript Core as of 2.8 + * @see https://github.com/Microsoft/TypeScript-Handbook/blame/master/pages/release%20notes/TypeScript%202.8.md#L203 */ export type NonNullable = T & {}; diff --git a/yarn.lock b/yarn.lock index 524751f..d76ed86 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From 803516bf88a5f7634c128869f4989ab817f62230 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Tue, 3 Apr 2018 12:02:08 -0700 Subject: [PATCH 2/7] PR Feedback - delete custom NonNullable now that public --- types/index.d.ts | 6 ------ types/non-nullable.ts | 5 ----- 2 files changed, 11 deletions(-) delete mode 100644 types/non-nullable.ts diff --git a/types/index.d.ts b/types/index.d.ts index cbc4b83..11c3e73 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -52,12 +52,6 @@ export type Overwrite = { */ export type NoInfer = T & { [K in keyof T]: T[K] }; -/** - * Deprecated: available in TypeScript Core as of 2.8 - * @see https://github.com/Microsoft/TypeScript-Handbook/blame/master/pages/release%20notes/TypeScript%202.8.md#L203 - */ -export type NonNullable = T & {}; - /** * Forgets contextual knowledge of partiality of keys. */ diff --git a/types/non-nullable.ts b/types/non-nullable.ts deleted file mode 100644 index d212334..0000000 --- a/types/non-nullable.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { NonNullable } from 'type-zoo'; - -declare const foo: NonNullable; - -const n: number = foo; From 0970ff447625bf602353af9815f66f9f3b785a46 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Tue, 3 Apr 2018 12:02:44 -0700 Subject: [PATCH 3/7] PR Feedback: Simplify Overwrite Impl. --- types/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 11c3e73..a50d585 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -31,11 +31,9 @@ export type Overlap = Diff>; * type from U only. * * @see https://github.com/pelotom/type-zoo/issues/2 - * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377692897 + * @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 */ -export type Overwrite = { - [P in Exclude]: T[P] -} & U; +export type Overwrite = Omit> & U; /** * Use to prevent a usage of type `T` from being inferred in other generics. From 8ff482467d3a81447a4cdb9102c95e32f936cd0b Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Tue, 3 Apr 2018 12:03:01 -0700 Subject: [PATCH 4/7] PR Feedback: make Diff an alias to Extract --- types/index.d.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index a50d585..c92ed7d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,11 +8,7 @@ * * @see https://github.com/Microsoft/TypeScript-Handbook/blame/master/pages/release%20notes/TypeScript%202.8.md#L245 */ -export type Diff = ( - & { [P in T]: P } - & { [P in U]: never } - & { [x: string]: never } -)[T]; +export type Diff = Exclude; /** * Drop keys `K` from `T`. @@ -24,7 +20,7 @@ export type Omit = Pick>; /** * Find the overlapping variants between two string unions. */ -export type Overlap = Diff>; +export type Overlap = Exclude>; /** * Like `T & U`, but where there are overlapping properties using the From 229ea303788fd1fa08d88db45984373ac465e614 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Tue, 3 Apr 2018 12:09:17 -0700 Subject: [PATCH 5/7] PR Feedback: Delete Diff & Overlap as now provided by Exclude & Extract --- README.md | 6 ------ types/diff.ts | 6 ------ types/index.d.ts | 15 --------------- types/overlap.ts | 6 ------ 4 files changed, 33 deletions(-) delete mode 100644 types/diff.ts delete mode 100644 types/overlap.ts diff --git a/README.md b/README.md index 75ce3b1..1d603c0 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,6 @@ See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 --- -### `Overlap` - -Find the overlapping variants between two string unions. - ---- - ### `Overwrite` Like `T & U`, but where there are overlapping properties using the type from `U` only. diff --git a/types/diff.ts b/types/diff.ts deleted file mode 100644 index e690aa3..0000000 --- a/types/diff.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Diff } from 'type-zoo'; - -declare const foo: Diff<'foo' | 'bar' | 'baz', 'bar'>; - -// $ExpectType "foo" | "baz" -foo; diff --git a/types/index.d.ts b/types/index.d.ts index c92ed7d..00df6b8 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,15 +1,5 @@ // TypeScript Version: 2.8 -/** - * Remove the variants of the second union of string literals from - * the first. - * - * TypeScript Documentation suggests that as of 2.8 you should use the built-in "Exclude" instead. - * - * @see https://github.com/Microsoft/TypeScript-Handbook/blame/master/pages/release%20notes/TypeScript%202.8.md#L245 - */ -export type Diff = Exclude; - /** * Drop keys `K` from `T`. * @@ -17,11 +7,6 @@ export type Diff = Exclude; */ export type Omit = Pick>; -/** - * Find the overlapping variants between two string unions. - */ -export type Overlap = Exclude>; - /** * Like `T & U`, but where there are overlapping properties using the * type from U only. diff --git a/types/overlap.ts b/types/overlap.ts deleted file mode 100644 index 03426bb..0000000 --- a/types/overlap.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Overlap } from 'type-zoo'; - -declare const foo: Overlap<'foo' | 'bar', 'bar' | 'baz'>; - -// $ExpectType "bar" -foo; From 034e1b75b82b17e8b757d0efe519b55d6d202435 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Mon, 23 Apr 2018 11:20:29 -0700 Subject: [PATCH 6/7] =?UTF-8?q?Update=20to=20new=20dtslint!=20=E2=80=94=20?= =?UTF-8?q?Tests=20pass!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- yarn.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 81b390c..1a491b4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "Tom Crockett", "license": "MIT", "devDependencies": { - "dtslint": "^0.2.0", + "dtslint": "^0.3.0", "typescript": "^2.8.1" }, "scripts": { diff --git a/yarn.lock b/yarn.lock index d76ed86..64caf44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,9 +89,9 @@ concat-map@0.0.1: 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" @@ -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: @@ -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: From e0c4955b395fa6e6b2b1614f13e233e80a3f181b Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Mon, 23 Apr 2018 13:37:54 -0700 Subject: [PATCH 7/7] PR Feedback: Simplify Overwrite --- README.md | 2 +- types/index.d.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d603c0..af85555 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 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 --- diff --git a/types/index.d.ts b/types/index.d.ts index 00df6b8..8397f5c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -11,10 +11,11 @@ export type Omit = Pick>; * 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 = Omit> & U; +export type Overwrite = Omit & U; /** * Use to prevent a usage of type `T` from being inferred in other generics.