Skip to content

Commit 0034589

Browse files
thebestnombigmontz
authored andcommitted
Add type assertion to is functions (#781)
Allow for easier use in typescript of is function
1 parent 81c3b53 commit 0034589

File tree

6 files changed

+74
-53
lines changed

6 files changed

+74
-53
lines changed

packages/core/src/graph-types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Object.defineProperty(
105105
* @param {Object} obj the object to test.
106106
* @return {boolean} `true` if given object is a {@link Node}, `false` otherwise.
107107
*/
108-
function isNode(obj: object): boolean {
108+
function isNode(obj: object): obj is Node {
109109
return hasIdentifierProperty(obj, NODE_IDENTIFIER_PROPERTY)
110110
}
111111

@@ -186,7 +186,7 @@ Object.defineProperty(
186186
* @param {Object} obj the object to test.
187187
* @return {boolean} `true` if given object is a {@link Relationship}, `false` otherwise.
188188
*/
189-
function isRelationship(obj: object): boolean {
189+
function isRelationship(obj: object): obj is Relationship {
190190
return hasIdentifierProperty(obj, RELATIONSHIP_IDENTIFIER_PROPERTY)
191191
}
192192

@@ -272,7 +272,7 @@ Object.defineProperty(
272272
* @param {Object} obj the object to test.
273273
* @return {boolean} `true` if given object is a {@link UnboundRelationship}, `false` otherwise.
274274
*/
275-
function isUnboundRelationship(obj: object): boolean {
275+
function isUnboundRelationship(obj: object): obj is UnboundRelationship {
276276
return hasIdentifierProperty(obj, UNBOUND_RELATIONSHIP_IDENTIFIER_PROPERTY)
277277
}
278278

@@ -320,7 +320,7 @@ Object.defineProperty(
320320
* @param {Object} obj the object to test.
321321
* @return {boolean} `true` if given object is a {@link PathSegment}, `false` otherwise.
322322
*/
323-
function isPathSegment(obj: object): boolean {
323+
function isPathSegment(obj: object): obj is PathSegment {
324324
return hasIdentifierProperty(obj, PATH_SEGMENT_IDENTIFIER_PROPERTY)
325325
}
326326

@@ -374,7 +374,7 @@ Object.defineProperty(
374374
* @param {Object} obj the object to test.
375375
* @return {boolean} `true` if given object is a {@link Path}, `false` otherwise.
376376
*/
377-
function isPath(obj: object): boolean {
377+
function isPath(obj: object): obj is Path {
378378
return hasIdentifierProperty(obj, PATH_IDENTIFIER_PROPERTY)
379379
}
380380

0 commit comments

Comments
 (0)