Skip to content

Commit 876b842

Browse files
authored
🤖 Merge PR DefinitelyTyped#72789 [n3] Turn type checking functions into type predicates by @opl-
1 parent 8874a5d commit 876b842

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎types/n3/index.d.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,11 @@ export interface StoreOptions {
373373
}
374374

375375
export namespace Util {
376-
function isNamedNode(value: RDF.Term | null): boolean;
377-
function isBlankNode(value: RDF.Term | null): boolean;
378-
function isLiteral(value: RDF.Term | null): boolean;
379-
function isVariable(value: RDF.Term | null): boolean;
380-
function isDefaultGraph(value: RDF.Term | null): boolean;
376+
function isNamedNode(value: RDF.Term | null): value is RDF.NamedNode;
377+
function isBlankNode(value: RDF.Term | null): value is RDF.BlankNode;
378+
function isLiteral(value: RDF.Term | null): value is RDF.Literal;
379+
function isVariable(value: RDF.Term | null): value is RDF.Variable;
380+
function isDefaultGraph(value: RDF.Term | null): value is RDF.DefaultGraph;
381381
function inDefaultGraph(value: RDF.Quad): boolean;
382382
function prefix(iri: RDF.NamedNode | string, factory?: RDF.DataFactory): PrefixedToIri;
383383
function prefixes(

‎types/n3/n3-tests.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,23 @@ function test_doc_utility() {
434434
const namedNode1: RDF.NamedNode = N3Util.prefix("http://www.w3.org/2000/01/rdf-schema#")("label");
435435
const namedNode2: RDF.NamedNode = N3Util.prefixes(prefixes)("rdfs")("label");
436436
const namedNode3: N3.NamedNode = N3Util.prefixes(prefixes)("rdfs")("label");
437+
438+
const term = N3.DataFactory.literal("Mickey Mouse") as RDF.Term;
439+
if (N3Util.isNamedNode(term)) {
440+
const namedNodeTerm: RDF.NamedNode = term;
441+
}
442+
if (N3Util.isBlankNode(term)) {
443+
const blankNodeTerm: RDF.BlankNode = term;
444+
}
445+
if (N3Util.isLiteral(term)) {
446+
const literalTerm: RDF.Literal = term;
447+
}
448+
if (N3Util.isVariable(term)) {
449+
const variableTerm: RDF.Variable = term;
450+
}
451+
if (N3Util.isDefaultGraph(term)) {
452+
const defaultGraphTerm: RDF.DefaultGraph = term;
453+
}
437454
}
438455

439456
function test_parser_options() {

0 commit comments

Comments
 (0)