type-plus 4.8.0 → 4.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ declare type Splitter<T extends AnyRecord> = Partial<{
4
4
  [k in keyof T]: T[k] | undefined;
5
5
  }>;
6
6
  export declare type Split<T extends AnyRecord, S extends AnyRecord> = {
7
- [k in keyof S]: S[k] extends undefined ? T[k] : NonNullable<T[k]> | S[k];
7
+ [k in keyof S]-?: S[k] extends undefined ? T[k] : NonNullable<T[k]> | S[k];
8
8
  };
9
9
  export declare function split<T extends AnyRecord, S1 extends Splitter<T>>(target: T, split1: S1): [
10
10
  Split<T, S1>,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-plus",
3
- "version": "4.8.0",
3
+ "version": "4.8.1",
4
4
  "description": "Provides additional types for TypeScript.",
5
5
  "homepage": "https://github.com/unional/type-plus",
6
6
  "bugs": {
@@ -35,6 +35,24 @@ test('can default with null', () => {
35
35
  isType.equal<true, number | null, typeof a>()
36
36
  })
37
37
 
38
+ test('remove optional/undefined when default is provided', () => {
39
+ interface S {
40
+ variant?: 'abc' | 'def'
41
+ }
42
+ const s: S = {}
43
+ const [a] = split(s, { variant: 'def' })
44
+ isType.equal<true, 'abc' | 'def', typeof a.variant>()
45
+ })
46
+
47
+ test('keep undefined when default is undefined', () => {
48
+ interface S {
49
+ variant?: 'abc' | 'def'
50
+ }
51
+ const s: S = {}
52
+ const [a] = split(s, { variant: undefined })
53
+ isType.equal<true, 'abc' | 'def' | undefined, typeof a.variant>()
54
+ })
55
+
38
56
 
39
57
  test('can default with false', () => {
40
58
  const s: { a?: number | boolean } = {}
@@ -4,7 +4,7 @@ import { reduceByKey } from './reduceKey'
4
4
 
5
5
  type Splitter<T extends AnyRecord> = Partial<{ [k in keyof T]: T[k] | undefined }>
6
6
  export type Split<T extends AnyRecord, S extends AnyRecord> = {
7
- [k in keyof S]: S[k] extends undefined ? T[k] : NonNullable<T[k]> | S[k]
7
+ [k in keyof S]-?: S[k] extends undefined ? T[k] : NonNullable<T[k]> | S[k]
8
8
  }
9
9
 
10
10
  /**