diff options
Diffstat (limited to 'assets/node_modules/read-pkg/node_modules/type-fest/source/merge-exclusive.d.ts')
-rw-r--r-- | assets/node_modules/read-pkg/node_modules/type-fest/source/merge-exclusive.d.ts | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/assets/node_modules/read-pkg/node_modules/type-fest/source/merge-exclusive.d.ts b/assets/node_modules/read-pkg/node_modules/type-fest/source/merge-exclusive.d.ts deleted file mode 100644 index 6290f42..0000000 --- a/assets/node_modules/read-pkg/node_modules/type-fest/source/merge-exclusive.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -// Helper type. Not useful on its own. -type Without<FirstType, SecondType> = {[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never}; - -/** -Create a type that has mutually exclusive properties. - -This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604). - -This type works with a helper type, called `Without`. `Without<FirstType, SecondType>` produces a type that has only keys from `FirstType` which are not present on `SecondType` and sets the value type for these keys to `never`. This helper type is then used in `MergeExclusive` to remove keys from either `FirstType` or `SecondType`. - -@example -``` -import {MergeExclusive} from 'type-fest'; - -interface ExclusiveVariation1 { - exclusive1: boolean; -} - -interface ExclusiveVariation2 { - exclusive2: string; -} - -type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>; - -let exclusiveOptions: ExclusiveOptions; - -exclusiveOptions = {exclusive1: true}; -//=> Works -exclusiveOptions = {exclusive2: 'hi'}; -//=> Works -exclusiveOptions = {exclusive1: true, exclusive2: 'hi'}; -//=> Error -``` -*/ -export type MergeExclusive<FirstType, SecondType> = - (FirstType | SecondType) extends object ? - (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) : - FirstType | SecondType; - |