diff --git a/types/clownface/clownface-tests.ts b/types/clownface/clownface-tests.ts index e74f780833..0f53c80fab 100644 --- a/types/clownface/clownface-tests.ts +++ b/types/clownface/clownface-tests.ts @@ -3,6 +3,7 @@ import Clownface = require('clownface/lib/Clownface'); import clownface = require('clownface'); const node: NamedNode = {}; +const blankNode: BlankNode = {}; const predicate: NamedNode = {}; const literal: Literal = {}; let term: Term = {}; @@ -13,8 +14,8 @@ const graph: NamedNode = {}; let cf = new Clownface({ dataset }); cf = new Clownface({ dataset, graph }); -cf = new Clownface({ dataset, term }); -cf = new Clownface({ dataset, term: [term, term] }); +const typedByTerm: Clownface = new Clownface({ dataset, term: node }); +const typedByTerms: Clownface = new Clownface({ dataset, term: [node, blankNode] }); cf = new Clownface({ dataset, value: 'foo' }); cf = new Clownface({ dataset, value: ['foo', 'bar'] }); cf = new Clownface({ dataset, term: [term, term], value: ['foo', 'bar'] }); @@ -50,10 +51,10 @@ cf = cf.addOut(predicate, child => { cf = cf.addOut(cf.node(predicate), cf.node(node)); // .blankNode -let blankNode: Clownface; -blankNode = cf.blankNode(); -blankNode = cf.blankNode('label'); -blankNode = cf.blankNode([ 'b1', 'b2' ]); +let blankContext: Clownface; +blankContext = cf.blankNode(); +blankContext = cf.blankNode('label'); +blankContext = cf.blankNode([ 'b1', 'b2' ]); // .deleteIn cf = cf.deleteIn(); @@ -74,6 +75,25 @@ cf = clownface({ dataset, term }); cf = clownface({ dataset, graph }); cf = clownface({ dataset, value: 'foo' }); +const termContext: Clownface = clownface({ + dataset, + term +}); + +const namedContext: Clownface = clownface({ + dataset, + term: node, +}); + +const maybeNamed: BlankNode | NamedNode = {}; +const altContext: Clownface = clownface({ + dataset, + term: maybeNamed, +}); + +const literalContext: clownface.SingleContextClownface = {}; +const deriveContextFromOtherGraph: Clownface = clownface(literalContext); + // .filter cf = cf.filter(() => true); cf = cf.filter((thus: Clownface) => true); diff --git a/types/clownface/index.d.ts b/types/clownface/index.d.ts index c57614c978..2318878c93 100644 --- a/types/clownface/index.d.ts +++ b/types/clownface/index.d.ts @@ -30,8 +30,8 @@ declare namespace clownface { value: string | string[]; } - interface WithTerm { - term: Term | Term[]; + interface WithTerm { + term: T | T[]; } interface Clownface { @@ -103,7 +103,11 @@ declare namespace clownface { } } -declare function clownface(options: clownface.ClownfaceInit & clownface.WithTerm | clownface.ClownfaceInit & clownface.WithValue): clownface.SafeClownface; -declare function clownface(options: clownface.ClownfaceInit): clownface.Clownface; +type ClownfaceInitWithNode = + clownface.ClownfaceInit & clownface.WithTerm | + clownface.ClownfaceInit & clownface.WithValue; + +declare function clownface(options: ClownfaceInitWithNode): clownface.SafeClownface; +declare function clownface(options: clownface.ClownfaceInit): clownface.Clownface; export = clownface; diff --git a/types/clownface/lib/Clownface.d.ts b/types/clownface/lib/Clownface.d.ts index 1b2236b372..7d0ee7ea6d 100644 --- a/types/clownface/lib/Clownface.d.ts +++ b/types/clownface/lib/Clownface.d.ts @@ -15,7 +15,7 @@ import { } from '..'; declare class Clownface implements ClownfaceContract { - constructor(options: ClownfaceInit & Partial & Partial); + constructor(options: ClownfaceInit & Partial> & Partial); readonly term: T | undefined; readonly terms: T[]; readonly value: string | undefined;