Skip to content

Commit

Permalink
feat(types): ExactOptionalPropertyTypes
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 3, 2022
1 parent 0999e72 commit 6a8cb77
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions src/types/exact-optional-property-types.ts
Original file line number Diff line number Diff line change
@@ -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<T extends ObjectPlain> = {
[K in keyof T]: Exclude<T[K], undefined> extends never
? T[K]
: Exclude<T[K], undefined>
} & {}

export type { ExactOptionalPropertyTypes as default }
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 6a8cb77

Please sign in to comment.