From 6a8cb7783fd0c4bd35a632b30253efc30d6b23cf Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 2 Dec 2022 19:41:06 -0500 Subject: [PATCH] feat(types): `ExactOptionalPropertyTypes` Signed-off-by: Lexus Drumgold --- .eslintrc.cjs | 6 +++++- src/types/exact-optional-property-types.ts | 21 +++++++++++++++++++++ src/types/index.ts | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/types/exact-optional-property-types.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 950f6026..80f3032f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -14,7 +14,11 @@ const config = { overrides: [ ...require('./.eslintrc.base.cjs').overrides, { - files: ['src/types/built-in.ts', 'src/types/overwrite.ts'], + files: [ + 'src/types/built-in.ts', + 'src/types/exact-optional-property-types.ts', + 'src/types/overwrite.ts' + ], rules: { '@typescript-eslint/ban-types': 0 } diff --git a/src/types/exact-optional-property-types.ts b/src/types/exact-optional-property-types.ts new file mode 100644 index 00000000..0c6ec28a --- /dev/null +++ b/src/types/exact-optional-property-types.ts @@ -0,0 +1,21 @@ +/** + * @file Type Definitions - ExactOptionalPropertyTypes + * @module tutils/types/ExactOptionalPropertyTypes + */ + +import type ObjectPlain from './object-plain' + +/** + * Removes `undefined` from optional properties. + * + * This is a workaround for [`Microsoft/TypeScript#46969`][1]. + * + * [1]: https://github.com/Microsoft/TypeScript/issues/46969 + */ +type ExactOptionalPropertyTypes = { + [K in keyof T]: Exclude extends never + ? T[K] + : Exclude +} & {} + +export type { ExactOptionalPropertyTypes as default } diff --git a/src/types/index.ts b/src/types/index.ts index 095f3d4a..1eff38a7 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -12,6 +12,10 @@ export type { default as Constructor } from './constructor' export type { default as ContinuousValue } from './continuous-value' export type { default as EmptyString } from './empty-string' export type { default as EmptyValue } from './empty-value' +// prettier-ignore +export type { + default as ExactOptionalPropertyTypes +} from './exact-optional-property-types' export type { default as FIXME } from './fixme' export type { default as IndexSignature } from './index-signature' export type { default as Join } from './join'