From 620642857d3238867f0defb62b31f59e0c8ed2df Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Fri, 11 Apr 2025 11:33:00 +0200 Subject: [PATCH] feat: equals type guards --- .changeset/wicked-keys-behave.md | 5 +++++ data-model.d.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/wicked-keys-behave.md diff --git a/.changeset/wicked-keys-behave.md b/.changeset/wicked-keys-behave.md new file mode 100644 index 0000000..2f5923f --- /dev/null +++ b/.changeset/wicked-keys-behave.md @@ -0,0 +1,5 @@ +--- +"@rdfjs/types": minor +--- + +Added [`this`-based type guards](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-based-type-guards) to `Term#equals` methods diff --git a/data-model.d.ts b/data-model.d.ts index 3ecb7d6..999f2cf 100644 --- a/data-model.d.ts +++ b/data-model.d.ts @@ -29,7 +29,7 @@ export interface NamedNode { * @param other The term to compare with. * @return True if and only if other has termType "NamedNode" and the same `value`. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -52,7 +52,7 @@ export interface BlankNode { * @param other The term to compare with. * @return True if and only if other has termType "BlankNode" and the same `value`. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -87,7 +87,7 @@ export interface Literal { * @return True if and only if other has termType "Literal" * and the same `value`, `language`, `direction`, and `datatype`. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -107,7 +107,7 @@ export interface Variable { * @param other The term to compare with. * @return True if and only if other has termType "Variable" and the same `value`. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -128,7 +128,7 @@ export interface DefaultGraph { * @param other The term to compare with. * @return True if and only if other has termType "DefaultGraph". */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -202,7 +202,7 @@ export interface BaseQuad { * @param other The term to compare with. * @return True if and only if the argument is a) of the same type b) has all components equal. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /** @@ -234,7 +234,7 @@ export interface Quad extends BaseQuad { * @param other The term to compare with. * @return True if and only if the argument is a) of the same type b) has all components equal. */ - equals(other: Term | null | undefined): boolean; + equals(other: T | null | undefined): this is T; } /**