type-plus 3.12.0 → 3.13.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.
Files changed (151) hide show
  1. package/README.md +1 -0
  2. package/lib/JSONTypes.js +10 -7
  3. package/lib/JSONTypes.js.map +1 -1
  4. package/lib/assertion/assertType.d.ts +0 -46
  5. package/lib/assertion/assertType.js +4 -4
  6. package/lib/assertion/assertType.js.map +1 -1
  7. package/lib/class/isConstructor.js +2 -2
  8. package/lib/class/isConstructor.js.map +1 -1
  9. package/lib/math/Subtract.d.ts +1 -1
  10. package/lib/nominal-types/Brand.js.map +1 -1
  11. package/lib/nominal-types/Flavor.js +1 -2
  12. package/lib/nominal-types/Flavor.js.map +1 -1
  13. package/lib/object/KnownKeys.d.ts +2 -1
  14. package/lib/object/KnownKeys.js +3 -0
  15. package/lib/object/KnownKeys.js.map +1 -1
  16. package/lib/object/facade.js +3 -0
  17. package/lib/object/facade.js.map +1 -1
  18. package/lib/object/getField.js.map +1 -1
  19. package/lib/object/hasKey.js.map +1 -1
  20. package/lib/object/mapProperties.js +1 -1
  21. package/lib/object/mapProperties.js.map +1 -1
  22. package/lib/object/omit.js +1 -1
  23. package/lib/object/omit.js.map +1 -1
  24. package/lib/object/pick.js +1 -1
  25. package/lib/object/pick.js.map +1 -1
  26. package/lib/object/typeOverrideIncompatible.d.ts +1 -1
  27. package/lib/object/typeOverrideIncompatible.js.map +1 -1
  28. package/lib/predicates/CanAssign.d.ts +2 -1
  29. package/lib/predicates/CanAssign.js.map +1 -1
  30. package/lib/predicates/index.d.ts +1 -0
  31. package/lib/predicates/index.js +1 -0
  32. package/lib/predicates/index.js.map +1 -1
  33. package/lib/predicates/isEmptyObject.d.ts +1 -0
  34. package/lib/predicates/isEmptyObject.js +3 -0
  35. package/lib/predicates/isEmptyObject.js.map +1 -0
  36. package/lib/predicates/isType.d.ts +4 -13
  37. package/lib/predicates/isType.js +3 -6
  38. package/lib/predicates/isType.js.map +1 -1
  39. package/lib/promise/isPromise.d.ts +1 -1
  40. package/lib/promise/isPromise.js +2 -1
  41. package/lib/promise/isPromise.js.map +1 -1
  42. package/lib/promise/mapSeries.js +1 -7
  43. package/lib/promise/mapSeries.js.map +1 -1
  44. package/lib/types/Array.d.ts +5 -5
  45. package/lib/types/Boolean.d.ts +8 -8
  46. package/lib/types/Null.d.ts +2 -2
  47. package/lib/types/Number.d.ts +6 -6
  48. package/lib/types/Number.js +10 -8
  49. package/lib/types/Number.js.map +1 -1
  50. package/lib/types/Object.d.ts +110 -126
  51. package/lib/types/Object.js +1 -1
  52. package/lib/types/Object.js.map +1 -1
  53. package/lib/types/Record.d.ts +1 -1
  54. package/lib/types/String.d.ts +6 -6
  55. package/lib/types/String.js +10 -8
  56. package/lib/types/String.js.map +1 -1
  57. package/lib/types/Symbol.d.ts +2 -2
  58. package/lib/types/Tuple.d.ts +1 -1
  59. package/lib/types/Tuple.js +10 -8
  60. package/lib/types/Tuple.js.map +1 -1
  61. package/lib/types/Union.d.ts +1 -1
  62. package/lib/types/Union.js +9 -7
  63. package/lib/types/Union.js.map +1 -1
  64. package/lib/types/analyze.js +3 -2
  65. package/lib/types/analyze.js.map +1 -1
  66. package/lib/types/check.js +2 -2
  67. package/lib/types/check.js.map +1 -1
  68. package/lib/types/conform.js +2 -2
  69. package/lib/types/conform.js.map +1 -1
  70. package/lib/types/getPlainAnalysisReport.js +28 -26
  71. package/lib/types/getPlainAnalysisReport.js.map +1 -1
  72. package/lib/types/optional.d.ts +134 -150
  73. package/lib/types/required.d.ts +270 -302
  74. package/lib/types/satisfy.js +2 -2
  75. package/lib/types/satisfy.js.map +1 -1
  76. package/libm/JSONTypes.js +1 -0
  77. package/libm/JSONTypes.js.map +1 -1
  78. package/libm/assertion/assertType.js.map +1 -1
  79. package/libm/class/isConstructor.js +2 -1
  80. package/libm/class/isConstructor.js.map +1 -1
  81. package/libm/nominal-types/Brand.js.map +1 -1
  82. package/libm/nominal-types/Flavor.js +1 -2
  83. package/libm/nominal-types/Flavor.js.map +1 -1
  84. package/libm/object/KnownKeys.js +3 -0
  85. package/libm/object/KnownKeys.js.map +1 -1
  86. package/libm/object/facade.js +3 -0
  87. package/libm/object/facade.js.map +1 -1
  88. package/libm/object/getField.js.map +1 -1
  89. package/libm/object/hasKey.js.map +1 -1
  90. package/libm/object/omit.js.map +1 -1
  91. package/libm/object/pick.js.map +1 -1
  92. package/libm/object/typeOverrideIncompatible.js.map +1 -1
  93. package/libm/predicates/CanAssign.js.map +1 -1
  94. package/libm/predicates/index.js +1 -0
  95. package/libm/predicates/index.js.map +1 -1
  96. package/libm/predicates/isEmptyObject.js +2 -0
  97. package/libm/predicates/isEmptyObject.js.map +1 -0
  98. package/libm/predicates/isType.js +4 -5
  99. package/libm/predicates/isType.js.map +1 -1
  100. package/libm/promise/isPromise.js +2 -1
  101. package/libm/promise/isPromise.js.map +1 -1
  102. package/libm/promise/mapSeries.js +1 -7
  103. package/libm/promise/mapSeries.js.map +1 -1
  104. package/libm/types/analyze.js +1 -2
  105. package/libm/types/analyze.js.map +1 -1
  106. package/package.json +29 -31
  107. package/src/JSONTypes.ts +2 -1
  108. package/src/UnionToIntersection.ts +1 -1
  109. package/src/assertion/assertType.spec.ts +4 -1
  110. package/src/assertion/assertType.ts +2 -2
  111. package/src/class/AnyConstructor.spec.ts +2 -2
  112. package/src/class/isConstructor.spec.ts +7 -2
  113. package/src/class/isConstructor.ts +4 -3
  114. package/src/function/AnyFunction.spec.ts +9 -9
  115. package/src/functional/Maybe.spec.ts +1 -1
  116. package/src/functional/Maybe.ts +1 -0
  117. package/src/math/Abs.spec.ts +1 -1
  118. package/src/math/Digit.spec.ts +2 -2
  119. package/src/math/Subtract.spec.ts +1 -1
  120. package/src/math/Subtract.ts +1 -1
  121. package/src/nominal-types/Brand.ts +3 -3
  122. package/src/nominal-types/Flavor.ts +3 -5
  123. package/src/object/ExcludePropType.spec.ts +1 -1
  124. package/src/object/KnownKeys.spec.ts +1 -1
  125. package/src/object/KnownKeys.ts +13 -5
  126. package/src/object/Partial.spec.ts +4 -5
  127. package/src/object/RecursiveIntersect.spec.ts +3 -3
  128. package/src/object/Required.spec.ts +2 -2
  129. package/src/object/facade.ts +3 -0
  130. package/src/object/getField.spec.ts +3 -3
  131. package/src/object/getField.ts +2 -2
  132. package/src/object/hasKey.ts +1 -1
  133. package/src/object/hasProperty.spec.ts +3 -3
  134. package/src/object/mapProperties.spec.ts +2 -2
  135. package/src/object/omit.spec.ts +5 -5
  136. package/src/object/omit.ts +1 -1
  137. package/src/object/pick.spec.ts +1 -1
  138. package/src/object/pick.ts +1 -1
  139. package/src/object/typeOverrideIncompatible.ts +1 -1
  140. package/src/predicates/CanAssign.ts +6 -3
  141. package/src/predicates/index.spec.ts +1 -3
  142. package/src/predicates/index.ts +1 -0
  143. package/src/predicates/isEmptyObject.spec.ts +15 -0
  144. package/src/predicates/isEmptyObject.ts +2 -0
  145. package/src/predicates/isType.spec.ts +2 -2
  146. package/src/predicates/isType.ts +7 -9
  147. package/src/promise/PromiseValue.spec.ts +1 -1
  148. package/src/promise/isPromise.ts +3 -2
  149. package/src/promise/mapSeries.ts +3 -7
  150. package/src/type-checker/AnyType.ts +1 -1
  151. package/src/types/satisfy.accept.ts +3 -1
@@ -22,13 +22,11 @@ export function flavor<F extends string>(type: F): <T>(subject: T) => Flavor<F,
22
22
  * Creates a branded value of specified type.
23
23
  */
24
24
  export function flavor<F extends string, T>(type: F, subject: T): Flavor<F, Widen<T>>
25
- export function flavor(type: string, subject?: any) {
26
- if (subject === undefined) {
27
- return function (subject: any) { return flavor(type, subject) }
28
- }
25
+ export function flavor(type: string, subject?: unknown) {
26
+ if (subject === undefined) return function <T>(subject: T) { return flavor(type, subject) }
29
27
  if (typeof subject === 'object' && subject !== null) {
30
28
  // if subject is not an object, the branding will exist only in type-level.
31
- (subject as any)[typeSym] = type
29
+ (subject as { [typeSym]: string })[typeSym] = type
32
30
  }
33
31
  return subject
34
32
  }
@@ -8,6 +8,6 @@ test('exclude type R from properties of T', () => {
8
8
 
9
9
  type CustomerAgeNotNull = ExcludePropType<Customer, null>
10
10
 
11
- const x: CustomerAgeNotNull = { age: 0 } as any
11
+ const x: CustomerAgeNotNull = { name: '', age: 0 }
12
12
  assertType.isNumber(x.age)
13
13
  })
@@ -35,5 +35,5 @@ test('empty record yields never', () => {
35
35
 
36
36
 
37
37
  function getKnownKeys<T>(_value: T): KnownKeys<T> {
38
- return {} as any
38
+ return {} as unknown as KnownKeys<T>
39
39
  }
@@ -1,8 +1,16 @@
1
- // by Klaus Meinhardt @ajafff
1
+ // Original by Klaus Meinhardt @ajafff
2
2
  // known from Gerrit Birkeland @Gerrit0
3
3
  // https://github.com/Microsoft/TypeScript/issues/25987#issuecomment-408339599
4
+
5
+ import { PrimitiveTypes } from '../PrimitiveTypes'
6
+
4
7
  // https://github.com/microsoft/TypeScript/issues/25987#issuecomment-441224690
5
- export type KnownKeys<T> = {
6
- [K in keyof T]: string extends K ? never : number extends K ? never : K
7
- // eslint-disable-next-line @typescript-eslint/ban-types
8
- } extends { [_ in keyof T]: infer U } ? ({} extends U ? never : U) : never;
8
+ export type KnownKeys<T> =
9
+ T extends PrimitiveTypes
10
+ ? never
11
+ : {
12
+ [K in keyof T]: string extends K ? never : number extends K ? never : K
13
+ } extends { [_ in keyof T]: infer U }
14
+ // eslint-disable-next-line @typescript-eslint/ban-types
15
+ ? ({} extends U ? never : U)
16
+ : never
@@ -2,7 +2,7 @@ import { assertType, PartialExcept, PartialOmit, PartialPick } from '..'
2
2
 
3
3
  test('work on primitive type', () => {
4
4
  type Foo = PartialPick<number, 'toFixed'>
5
- const x: Foo = 1 as any
5
+ const x: Foo = 1
6
6
  assertType<typeof x['toFixed']>(1 as unknown as 1['toFixed'] | undefined)
7
7
  })
8
8
 
@@ -13,7 +13,7 @@ test('make picked properties optional', () => {
13
13
  c: number,
14
14
  }
15
15
 
16
- const y: PartialPick<Foo, 'a'> = { b: 1, c: 2 } as any
16
+ const y: PartialPick<Foo, 'a'> = { b: 1, c: 2 }
17
17
 
18
18
  y.a = undefined
19
19
  assertType.noUndefined(y.b)
@@ -27,8 +27,7 @@ test('make not specified properties optional', () => {
27
27
  c: number,
28
28
  }
29
29
 
30
- const y: PartialExcept<Foo, 'a'> = { a: 1 } as any
31
-
30
+ const y: PartialExcept<Foo, 'a'> = { a: 1 }
32
31
  assertType.noUndefined(y.a)
33
32
  y.b = undefined
34
33
  y.c = undefined
@@ -42,7 +41,7 @@ test('make not specified properties optional', () => {
42
41
  c: number,
43
42
  }
44
43
 
45
- const y: PartialOmit<Foo, 'a'> = { a: 1 } as any
44
+ const y: PartialOmit<Foo, 'a'> = { a: 1 }
46
45
 
47
46
  assertType.noUndefined(y.a)
48
47
  y.b = undefined
@@ -1,7 +1,7 @@
1
1
  import { RecursiveIntersect } from '..'
2
2
 
3
3
  test('add object type to types', () => {
4
- type U = { u: number };
4
+ type U = { u: number }
5
5
 
6
6
  acceptU(addU('a'))
7
7
  acceptU(addU(1))
@@ -29,8 +29,8 @@ test('add object type to types', () => {
29
29
  // acceptU(comArr[0])
30
30
  // acceptU(comArr[0].x)
31
31
 
32
- function addU<T>(x: T): RecursiveIntersect<typeof x, U> {
33
- return x as any
32
+ function addU<T>(x: T): RecursiveIntersect<T, U> {
33
+ return x as any as RecursiveIntersect<T, U>
34
34
  }
35
35
 
36
36
  function acceptU(x: U) {
@@ -7,7 +7,7 @@ test('make picked properties required', () => {
7
7
  c: number,
8
8
  }
9
9
 
10
- const y: RequiredPick<Foo, 'a'> = { a: 1, c: 2 } as any
10
+ const y: RequiredPick<Foo, 'a'> = { a: 1, c: 2 }
11
11
 
12
12
  assertType.noUndefined(y.a)
13
13
  y.b = undefined
@@ -21,7 +21,7 @@ test('make not picked properties required', () => {
21
21
  c: number,
22
22
  }
23
23
 
24
- const y: RequiredExcept<Foo, 'a'> = { b: 1, c: 2 } as any
24
+ const y: RequiredExcept<Foo, 'a'> = { b: 1, c: 2 }
25
25
 
26
26
  y.a = undefined
27
27
  assertType.noUndefined(y.b)
@@ -19,14 +19,17 @@ export function facade<T extends AnyRecord>(subject: T, ...props: (keyof T)[]) {
19
19
  return props.reduce((p, k) => {
20
20
  const prop = subject[k]
21
21
  if (typeof prop === 'function') {
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
22
23
  p[k] = prop.bind(subject)
23
24
  }
24
25
  else {
25
26
  Object.defineProperty(p, k, {
26
27
  get() {
28
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
27
29
  return subject[k]
28
30
  },
29
31
  set(value: any) {
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-assignment
30
33
  return subject[k] = value
31
34
  },
32
35
  })
@@ -1,12 +1,12 @@
1
1
  import { getField } from '..'
2
2
 
3
3
  test('support undefined', () => {
4
- const sub: { a: number } | undefined = { a: 1 } as any
4
+ const sub: { a: number } | undefined = { a: 1 }
5
5
  expect(getField(sub, 'a')).toBe(1)
6
6
  })
7
7
 
8
8
  test('support null', () => {
9
- const sub: { a: number } | null = { a: 1 } as any
9
+ const sub: { a: number } | null = { a: 1 }
10
10
  expect(getField(sub, 'a')).toBe(1)
11
11
  })
12
12
 
@@ -16,6 +16,6 @@ test('can specify default value', () => {
16
16
  })
17
17
 
18
18
  test('get from union keys', () => {
19
- const sub: { a: number, b: string } | { a: number, c: string } = { a: 1, b: 'b' } as any
19
+ const sub: { a: number, b: string } | { a: number, c: string } = { a: 1, b: 'b' }
20
20
  expect(getField(sub, 'b')).toBe('b')
21
21
  })
@@ -16,6 +16,6 @@ export function getField<
16
16
  TX extends Exclude<T, undefined | null>,
17
17
  K extends UnionKeys<TX>,
18
18
  DV extends Exclude<TX[K], undefined>
19
- >(subject: T, key: K, defaultValue?: DV): DV {
20
- return subject && (subject as any)[key] || defaultValue
19
+ >(subject: T, key: K, defaultValue?: DV) {
20
+ return subject && (subject as unknown as { [k in K]: TX[K] | DV })[key] || defaultValue
21
21
  }
@@ -3,5 +3,5 @@ import { AnyRecord } from './AnyRecord'
3
3
  export type HasKey<T, K, Then = true, Else = false> = K extends keyof T ? Then : Else
4
4
 
5
5
  export function hasKey<T extends AnyRecord, K extends string>(subject: T, ...keys: K[]): HasKey<T, K> {
6
- return !keys.some(key => !subject[key]) as any
6
+ return !keys.some(key => !subject[key]) as unknown as HasKey<T, K>
7
7
  }
@@ -3,13 +3,13 @@ import { hasProperty } from '..'
3
3
  test('hasProperty', () => {
4
4
  type X = { name: string } & ({ a: 1 } | { b: 2 })
5
5
 
6
- const x: X = { name: 'n', a: 1 } as any
6
+ const x: X = { name: 'n', a: 1 }
7
7
 
8
8
  if (hasProperty(x, 'a'))
9
9
  expect(x.a).toBe(1)
10
10
 
11
- const y: X = { name: 'n', b: 2 } as any
11
+ const y: X = { name: 'n', b: 2 }
12
12
 
13
13
  if (hasProperty(y, 'b'))
14
14
  expect(y.b).toBe(2)
15
- });
15
+ })
@@ -1,12 +1,12 @@
1
1
  import { mapProperties } from '..'
2
2
 
3
3
  test('basic usage', () => {
4
- const actual = mapProperties({ a: 1, b: 2 }, (v, k) => k + (v * 2))
4
+ const actual = mapProperties({ a: 1, b: 2 }, (v, k) => k + String((v * 2)))
5
5
  expect(actual).toEqual({ a: 'a2', b: 'b4' })
6
6
  })
7
7
 
8
8
  test('mixed type', () => {
9
- const actual = mapProperties({ a: 1, b: 'b' }, (v, k) => k + v)
9
+ const actual = mapProperties({ a: 1, b: 'b' }, (v, k) => k + String(v))
10
10
  expect(actual).toEqual({ a: 'a1', b: 'bb' })
11
11
  })
12
12
 
@@ -14,12 +14,12 @@ describe('Omit', () => {
14
14
  }
15
15
 
16
16
  type Actual = Omit<Foo, 'c'>
17
- const a: Actual = { a: 0, b: '' } as any
17
+ const a: Actual = { a: 0, b: '' }
18
18
  assertType.isNumber(a.a)
19
19
  assertType.isString(a.b)
20
20
 
21
21
  type Revert = Omit<Foo, keyof Actual>
22
- const r: Revert = { c: false } as any
22
+ const r: Revert = { c: false }
23
23
  assertType.isBoolean(r.c)
24
24
  })
25
25
 
@@ -38,7 +38,7 @@ describe('Omit', () => {
38
38
  payload: string,
39
39
  }
40
40
 
41
- const x: Omit<Action, 'id'> = {} as any
41
+ const x: Omit<Action, 'id'> = { type: 'return', payload: '' }
42
42
 
43
43
  const actions: Action[] = []
44
44
 
@@ -92,13 +92,13 @@ describe('Except()', () => {
92
92
  }
93
93
 
94
94
  type Actual = Except<Foo, 'c'>
95
- const a: Actual = { a: 0, b: '' } as any
95
+ const a: Actual = { a: 0, b: '' }
96
96
  assertType.isNumber(a.a)
97
97
  assertType.isString(a.b)
98
98
 
99
99
  // tslint:disable-next-line: deprecation
100
100
  type Revert = Except<Foo, keyof Actual>
101
- const r: Revert = { c: false } as any
101
+ const r: Revert = { c: false }
102
102
  assertType.isBoolean(r.c)
103
103
  })
104
104
  })
@@ -32,5 +32,5 @@ export function omit<T extends AnyRecord>(subject: T, ...props: Array<UnionKeys<
32
32
  return reduceByKey(subject, (p, k) => {
33
33
  if (props.indexOf(k) === -1) p[k] = subject[k]
34
34
  return p
35
- }, {} as any)
35
+ }, {} as AnyRecord)
36
36
  }
@@ -21,7 +21,7 @@ test('distributive pick', () => {
21
21
  payload: string,
22
22
  }
23
23
 
24
- const x: Pick<Action, 'type' | 'payload'> = {} as any
24
+ const x: Pick<Action, 'type' | 'payload'> = { type: 'invoke', payload: [] }
25
25
 
26
26
  const actions: Action[] = []
27
27
 
@@ -18,7 +18,7 @@ export function pick<T extends AnyRecord>(subject: T, ...props: Array<UnionKeys<
18
18
  return reduceByKey(subject, (p, k) => {
19
19
  if (props.indexOf(k) >= 0) p[k] = subject[k]
20
20
  return p
21
- }, {} as any)
21
+ }, {} as T)
22
22
  }
23
23
 
24
24
  /**
@@ -5,6 +5,6 @@ export function typeOverrideIncompatible<A extends AnyRecord>() {
5
5
  return {
6
6
  ...source,
7
7
  ...override,
8
- } as any
8
+ }
9
9
  }
10
10
  }
@@ -1,12 +1,15 @@
1
1
  import { NotExtendable } from './Extends'
2
+ import { IsEmptyObject } from './isEmptyObject'
2
3
 
3
4
  /**
4
5
  * Can `A` assign to `B`
5
6
  */
6
7
  export type CanAssign<A, B, Then = true, Else = false> =
7
- boolean extends A ?
8
- boolean extends B ? Then : Else :
9
- A extends B ? Then : Else
8
+ IsEmptyObject<A> extends true
9
+ ? Record<string, unknown> extends B ? Then : Else
10
+ : boolean extends A
11
+ ? (boolean extends B ? Then : Else)
12
+ : A extends B ? Then : Else
10
13
 
11
14
 
12
15
  export type IsAssign<A, B, Then = true, Else = false> = CanAssign<A, B, Then, Else>
@@ -1,5 +1,4 @@
1
- import { IsBoolean } from '.'
2
- import { IsLiteral, isType } from '..'
1
+ import { IsAny, IsBoolean, IsLiteral, isType, PrimitiveTypes } from '..'
3
2
 
4
3
  describe('IsLiteral<T>', () => {
5
4
  test('`number` is not literal', () => {
@@ -37,7 +36,6 @@ describe('IsBoolean<T>', () => {
37
36
  isType.equal<true, 'no', IsBoolean<1, 'yes', 'no'>>()
38
37
  })
39
38
  })
40
- import { IsAny, PrimitiveTypes } from '..'
41
39
 
42
40
  describe('IsAny<T>', () => {
43
41
  test('any is true', () => {
@@ -4,6 +4,7 @@ export * from './Extends'
4
4
  export * from './If'
5
5
  export * from './isType'
6
6
  export * from './logical'
7
+ export * from './isEmptyObject'
7
8
 
8
9
  import { IsExtend } from './Extends'
9
10
 
@@ -0,0 +1,15 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ import { IsEmptyObject } from '..'
3
+ import { isType } from './isType'
4
+
5
+ test('true for {}', () => {
6
+ isType.t<IsEmptyObject<{}>>()
7
+ })
8
+ test('false for everything else', () => {
9
+ isType.f<IsEmptyObject<undefined>>()
10
+ isType.f<IsEmptyObject<false>>()
11
+ isType.f<IsEmptyObject<0>>()
12
+ isType.f<IsEmptyObject<''>>()
13
+ isType.f<IsEmptyObject<{ a: 1 }>>()
14
+ })
15
+
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ export type IsEmptyObject<T> = T extends {} ? {} extends T ? true : false : false
@@ -27,7 +27,7 @@ describe('isType()', () => {
27
27
  assertType<boolean>(s)
28
28
  })
29
29
  test('exclude type if type guard fails', () => {
30
- const s: string | number = 1 as any
30
+ const s: string | number = 1
31
31
  if (isType<string>(s, s => typeof s === 'string')) {
32
32
  assertType<string>(s)
33
33
  }
@@ -44,7 +44,7 @@ describe('isType()', () => {
44
44
  })
45
45
  test('Class as validator fails', () => {
46
46
  class Foo { a() { } }
47
- const s: Foo | number = 1 as any
47
+ const s: Foo | number = 1
48
48
  if (isType(s, Foo)) {
49
49
  assertType<Foo>(s)
50
50
  }
@@ -1,10 +1,10 @@
1
- import { isConstructor } from '../class'
1
+ import { AnyConstructor, isConstructor } from '../class'
2
2
  import { Equal } from './Equal'
3
3
 
4
4
  export function isType<T>(subject: T): subject is T
5
5
  export function isType<T>(subject: unknown, validator: (s: T) => boolean): subject is T
6
- export function isType<T extends new (...args: any) => any>(subject: unknown, constructor: T): subject is InstanceType<T>
7
- export function isType(subject: any, validator?: any) {
6
+ export function isType<T extends AnyConstructor>(subject: unknown, constructor: T): subject is InstanceType<T>
7
+ export function isType(subject: unknown, validator?: AnyConstructor | ((s: unknown) => boolean)) {
8
8
  if (validator) {
9
9
  if (isConstructor(validator))
10
10
  return subject instanceof validator
@@ -14,13 +14,11 @@ export function isType(subject: any, validator?: any) {
14
14
  return true
15
15
  }
16
16
 
17
- const sym = Symbol()
18
-
19
- isType.t = function <T extends true>(subject: T = sym as any) {
20
- return (subject as any) === sym || subject === true
17
+ isType.t = function <T extends true>(subject?: T) {
18
+ return subject === undefined || subject === true
21
19
  }
22
- isType.f = function <T extends false>(subject: T = sym as any) {
23
- return (subject as any) === sym || subject === false
20
+ isType.f = function <T extends false>(subject?: T) {
21
+ return subject === undefined || subject === false
24
22
  }
25
23
 
26
24
  /**
@@ -1,6 +1,6 @@
1
1
  import { assertType, PromiseValue } from '..'
2
2
 
3
3
  test('extract value from Promise', () => {
4
- const y: PromiseValue<Promise<string>> = '' as any
4
+ const y: PromiseValue<Promise<string>> = ''
5
5
  assertType.isString(y)
6
6
  })
@@ -1,3 +1,4 @@
1
- export function isPromise<R = any>(subject: any): subject is Promise<R> {
2
- return !!subject && typeof subject.then === 'function'
1
+ export function isPromise<R = any>(subject: unknown): subject is Promise<R> {
2
+ // @ts-ignore
3
+ return !!subject && typeof subject['then'] === 'function'
3
4
  }
@@ -1,9 +1,5 @@
1
1
  export function mapSeries<R, T = any>(values: T[], fn: (value: T) => Promise<R>): Promise<R[]> {
2
- const results: R[] = []
3
- return values.reduce((p, v) => {
4
- return p.then(() => fn(v)).then((r: any) => {
5
- results.push(r)
6
- return results
7
- })
8
- }, Promise.resolve() as any)
2
+ return values.reduce(
3
+ (p, v) => p.then(r => fn(v).then(v => (r.push(v), r))),
4
+ Promise.resolve<R[]>([]))
9
5
  }
@@ -9,5 +9,5 @@ export const any: Any = { type: 'any', value: undefined }
9
9
  export const anySpec: TypeSpec<Any> = {
10
10
  type: any,
11
11
  toAnalysis: (options, value, _subject) => ({ type: 'any', value }),
12
- toNative: (value) => value as any
12
+ toNative: (value) => value
13
13
  }
@@ -29,7 +29,9 @@ const eslint = T.object.create({
29
29
 
30
30
  baseline('fixtures/eslint', ({ caseName, caseFolder }) => {
31
31
  test(`eslint ${caseName}`, () => {
32
- const config = JSON.parse(fs.readFileSync(`${path.join(caseFolder, caseName)}`, 'utf-8'))
32
+ const config: unknown = JSON.parse(
33
+ fs.readFileSync(`${path.join(caseFolder, caseName)}`, 'utf-8')
34
+ )
33
35
 
34
36
  if (!T.satisfy(eslint, config)) fail('should satisfy')
35
37
  })