type-plus
Advanced tools
Comparing version 1.30.1 to 1.31.0
@@ -0,1 +1,2 @@ | ||
import { UnionKeys } from './UnionKeys'; | ||
/** | ||
@@ -20,2 +21,3 @@ * assert the subject satisfies the specified type T | ||
var isNever: (value: never) => void; | ||
var hasProperty: <T, P extends UnionKeys<T>>(value: T, prop: P) => asserts value is T & Record<P, T[P]>; | ||
} | ||
@@ -22,0 +24,0 @@ /** |
@@ -22,2 +22,4 @@ "use strict"; | ||
assertType.isNever = noop; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
assertType.hasProperty = function hasProperty(value, prop) { }; | ||
// assertType.hasProperty = <T>(value: T, propertyName: KeyTypes) | ||
@@ -24,0 +26,0 @@ function noop() { return; } |
@@ -0,1 +1,2 @@ | ||
import { UnionKeys } from './UnionKeys'; | ||
/** | ||
@@ -20,2 +21,3 @@ * assert the subject satisfies the specified type T | ||
var isNever: (value: never) => void; | ||
var hasProperty: <T, P extends UnionKeys<T>>(value: T, prop: P) => asserts value is T & Record<P, T[P]>; | ||
} | ||
@@ -22,0 +24,0 @@ /** |
@@ -19,2 +19,4 @@ /** | ||
assertType.isNever = noop; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
assertType.hasProperty = function hasProperty(value, prop) { }; | ||
// assertType.hasProperty = <T>(value: T, propertyName: KeyTypes) | ||
@@ -21,0 +23,0 @@ function noop() { return; } |
{ | ||
"name": "type-plus", | ||
"version": "1.30.1", | ||
"version": "1.31.0", | ||
"description": "Provides additional types for `typescript`.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/unional/type-plus", |
@@ -103,2 +103,3 @@ # type-plus | ||
- `assertType.noXXX(value)`: ensure typeof `value` does not contain `XXX`. i.e. cannot assign `XXX` to `value`. | ||
- `assertType.hasProperty(value, prop)`: assert `value` has property `prop`. This will pick the correct union type. | ||
- `typeAssert.*` (deprecated) replaced by `assertType`. | ||
@@ -105,0 +106,0 @@ - `typeAssertion<T>()`: creates a type assertion function of type `T` |
@@ -171,1 +171,16 @@ import { assertType, typeAssertion } from '.'; | ||
}) | ||
describe('hasProperty', () => { | ||
type X = { name: string } & ({ a: 1 } | { b: 2 }) | ||
const x: X = { name: 'n', a: 1 } as any | ||
assertType.hasProperty(x, 'a') | ||
expect(x.a).toBe(1) | ||
const y: X = { name: 'n', b: 2 } as any | ||
assertType.hasProperty(y, 'b') | ||
expect(y.b).toBe(2) | ||
}); |
@@ -0,1 +1,3 @@ | ||
import { UnionKeys } from './UnionKeys' | ||
/** | ||
@@ -20,2 +22,6 @@ * assert the subject satisfies the specified type T | ||
assertType.isNever = noop as (value: never) => void | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
assertType.hasProperty = function hasProperty<T, P extends UnionKeys<T>>(value: T, prop: P): asserts value is T & Record<P, T[P]> { } | ||
// assertType.hasProperty = <T>(value: T, propertyName: KeyTypes) | ||
@@ -22,0 +28,0 @@ function noop() { return } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146050
2364
189