mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
fix: preserve term generic type when constructing from another graph (#41606)
* fix: preserve term generic type when constructing from another graph * style: revert unwanted whitespace change
This commit is contained in:
committed by
Eli Barzilay
parent
cb5127eecf
commit
5101bd7b8a
@@ -3,6 +3,7 @@ import Clownface = require('clownface/lib/Clownface');
|
||||
import clownface = require('clownface');
|
||||
|
||||
const node: NamedNode = <any> {};
|
||||
const blankNode: BlankNode = <any> {};
|
||||
const predicate: NamedNode = <any> {};
|
||||
const literal: Literal = <any> {};
|
||||
let term: Term = <any> {};
|
||||
@@ -13,8 +14,8 @@ const graph: NamedNode = <any> {};
|
||||
|
||||
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<DatasetCore, NamedNode> = new Clownface({ dataset, term: node });
|
||||
const typedByTerms: Clownface<DatasetCore, NamedNode | BlankNode> = 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<DatasetCore, NamedNode> = clownface({
|
||||
dataset,
|
||||
term: node,
|
||||
});
|
||||
|
||||
const maybeNamed: BlankNode | NamedNode = <any> {};
|
||||
const altContext: Clownface<DatasetCore, BlankNode | NamedNode> = clownface({
|
||||
dataset,
|
||||
term: maybeNamed,
|
||||
});
|
||||
|
||||
const literalContext: clownface.SingleContextClownface<Dataset, Literal> = <any> {};
|
||||
const deriveContextFromOtherGraph: Clownface<Dataset, Literal> = clownface(literalContext);
|
||||
|
||||
// .filter
|
||||
cf = cf.filter(() => true);
|
||||
cf = cf.filter((thus: Clownface) => true);
|
||||
|
||||
Vendored
+8
-4
@@ -30,8 +30,8 @@ declare namespace clownface {
|
||||
value: string | string[];
|
||||
}
|
||||
|
||||
interface WithTerm {
|
||||
term: Term | Term[];
|
||||
interface WithTerm<T extends Term = Term> {
|
||||
term: T | T[];
|
||||
}
|
||||
|
||||
interface Clownface<D extends DatasetCore = DatasetCore, T extends Term = Term> {
|
||||
@@ -103,7 +103,11 @@ declare namespace clownface {
|
||||
}
|
||||
}
|
||||
|
||||
declare function clownface<D extends DatasetCore>(options: clownface.ClownfaceInit<D> & clownface.WithTerm | clownface.ClownfaceInit<D> & clownface.WithValue): clownface.SafeClownface<D>;
|
||||
declare function clownface<D extends DatasetCore>(options: clownface.ClownfaceInit<D>): clownface.Clownface<D>;
|
||||
type ClownfaceInitWithNode<D extends DatasetCore, T extends Term> =
|
||||
clownface.ClownfaceInit<D> & clownface.WithTerm<T> |
|
||||
clownface.ClownfaceInit<D> & clownface.WithValue;
|
||||
|
||||
declare function clownface<D extends DatasetCore, T extends Term = Term>(options: ClownfaceInitWithNode<D, T>): clownface.SafeClownface<D, T>;
|
||||
declare function clownface<D extends DatasetCore, T extends Term = Term>(options: clownface.ClownfaceInit<D, T>): clownface.Clownface<D, T>;
|
||||
|
||||
export = clownface;
|
||||
|
||||
Vendored
+1
-1
@@ -15,7 +15,7 @@ import {
|
||||
} from '..';
|
||||
|
||||
declare class Clownface<D extends DatasetCore = DatasetCore, T extends Term = Term> implements ClownfaceContract<D, T> {
|
||||
constructor(options: ClownfaceInit & Partial<WithTerm> & Partial<WithValue>);
|
||||
constructor(options: ClownfaceInit & Partial<WithTerm<T>> & Partial<WithValue>);
|
||||
readonly term: T | undefined;
|
||||
readonly terms: T[];
|
||||
readonly value: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user