You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add and Improve type guards for is methods (#1037)
* Add and Improve type guards for `is` methods
The following methods were update to include type-guards and improve the generics over when using the type-guards:
* isNode
* isRelationship
* isUnboundRelationship
* isPath
* isPathSegment
* isPoint
* isDuration
* isLocalTime
* isTime
* isDate
* isLocalDateTime
* isDateTime
Usage example without generics:
```
function handleDuration(duration: unknown) {
if (isDuration(duration)) {
// from this point i can access the duration properties
// and methods without issue
const months: Integer = duration.months
} else {
// this is not a duration object
// @ts-expect-error
const months = duration.months
}
}
```
Usage example with generics:
The following methods were update to include type-guards and improve the generics over when using the type-guards:
* isNode
* isRelationship
* isUnboundRelationship
* isPath
* isPathSegment
* isPoint
* isDuration
* isLocalTime
* isTime
* isDate
* isLocalDateTime
* isDateTime
Usage example without generics:
```typescript
function handleDuration(duration: unknown) {
if (isDuration(duration)) {
// from this point i can access the duration properties
// and methods without issue
const months: Integer = duration.months
} else {
// this is not a duration object
// @ts-expect-error
const months = duration.months
}
}
```
Usage example with generics:
```typescript
function handleDuration(duration: unknown) {
if (isDuration<number>(duration)) {
// from this point i can access the duration properties
// and methods without issue
const months: number = duration.months
// @ts-expect-error
const intMonths: Integer = duration.months
} else {
// this is not a duration object
// @ts-expect-error
const months = duration.months
}
}
```
⚠️ Generic types miss-match in runtime will not trigger errors.
Co-authored-by: Robsdedude <dev@rouvenbauer.de>
test.each(nonUnboundRelationships())('should not consider a non-unbound relationship object as unbound relationship',(nonUnboundRelationship: unknown)=>{
0 commit comments