linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
566 stars 146 forks source link

Typescript: Type 'NamedNode' is missing the following properties from type 'NamedNode': classOrder, dir, site, doc, and 9 more #451

Open eroux opened 4 years ago

eroux commented 4 years ago

When doing the following:

import * as rdf from 'rdflib'
const exfoo :rdf.NamedNode = rdf.Namespace("http://example.com/")("foo")

I'm getting:

Type 'NamedNode' is missing the following properties from type 'NamedNode': classOrder, dir, site, doc, and 9 more.  TS2740

    20 | 
    21 | 
  > 22 | const exfoo :rdf.NamedNode = rdf.Namespace("http://example.com/")("foo")
       |       ^
    23 | 

which is a bit bizarre... I believe this comes from the multiple declarations of NamedNode, once as an interface here and once as a class here.

The interface is the returned type of rdf.Namespace("http://example.com/")("foo") as seen here, while the class is what gets exported by the rdflib module here.

Effectively there seems to be no valid type for exfoo that I could use, as the NamedNode interface is not exported.

Is it possible to export the interfaces, or implement any another appropriate solution?

renyuneyun commented 2 days ago

I'm having the same issue and found here. Can't believe it's an old issue of 4 years without any response (at least clarification)...

(Note that in the current version of rdflib, you can do import { NamedNode } from 'rdflib/lib/tf-types'; to resolve the original issue.)

I understand the reason for having a separete NamedNode interface, which is to be compatible with the rdf.js specification. However, the defined NamedNode interface is not compatible with that from @rdfjs/types, the reference type definition. In particular, it misses the ? aspect of the equals() method.

I'm not sure if this is a version issue, as I'm not experienced enough with rdfjs either. But this inconsistency should be resolved to remain compatible.