-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with types #397
Comments
Given all of the above, and especially that they are a superset: we should just fix the TypeScript typings such that they are compatible. This is a bug in the typings, nothing more than that.
Exactly. Or even better perhaps, with generics. So the question very concretely becomes: what are the points where they are incompatible now, and how do we fix them? You already gave the example:
Maybe this is a mistake in RDF/JS and it should rather be "something extending named node / blank node / …", through generics or another mechanism. |
(I wonder why ObjectType allows for Empty -- what does that mean? That undefined can be passes as parameter, or that a property on an object can be missing? Just a side wondering) Tell me how Typescript works. If we declare the QuadObject to be Expression (say), and declare all of Term, NamedNode , BlankNode, Literal, Variable, and also in RDFLIB types Collection, Graph, maybe Set, etc to be subclasses of Expression, does that work>? Or does TS need to have a particular closed set of subclasses of any class to be defined? |
The ideal would be that
|
That should be possible using generics. I.e., if you pass an rdflib object into an rdflib method, it will give you an rdflib object back.
Check.
Yes. @megoth Are you sufficiently familiar with TypeScript to give this ago, or would you need help? |
@RubenVerborgh I have enough to give this another go, but am occupied with another task until Thursday. Will try to get on it at once after that, and might contact you if I need some help. |
@RubenVerborgh I've given this a new go, but keep running into changes that forces me to change a bunch of files and I get the feeling that I'm reverting a lot of the work that @joepio did to ensure RDF/JS support. As we discussed offline, I hope you're able to give this a go tomorrow, to see if you understand how to go about this. I've done some work on the fix-types2 branch, that should fix the inconsistencies in classes that extend other classes (i.e. problem 1 described originally) - I haven't verified this changes with Tim, so some more changes on that branch might come. I've also pushed some partial work to the fix-types2b branch, in case I'm going the right way on it and you want to continue it. |
One of the tests I wanted to write after bc4beb6 is (at the top of // The rdflib.js DataFactory is an RDF/JS DataFactory
const factory = DataFactory;
const factory2: RdfJs.DataFactory = factory; However, this fails, the primary reason being that |
@RubenVerborgh this looks very good, definitely going the right direction. I'm getting some errors when I try to use it with the current Solid UI:
Some of them are bugs in Solid UI, but thought it could be useful for you to see the output I currently get. In any case, there are 18 errors altogether, which is better than my 203 errors that I had when I tried fixing this 😼 I'll work on fixing the bugs in Solid UI, and get back to you when I have a list with the remaining errors. |
Nevermind, it seems that all bugs were originating in Solid UI. Seems like this is working then, I'll let you know if I find anything else. |
Good! In any case, the typings in rdflib.js are over-complex currently. We likely just want to import the RDF/JS typings and take it from there, as opposed to the 3–4 layers of typings that currently exist. It's bound to byte us at some point. |
@megoth Have the problems been mitigated? Then we might want to close this issue. |
Yes, thank you, I think https://github.com/linkeddata/rdflib.js/tree/feature/extended-typing should solve the problems. Perhaps create a PR for it to be merged into master? I'll close this issue for now, please reopen if necessary. |
in #406 |
I've done some initial work to try to fix type errors that pop up when using the work on the master branch (e.g. for Solid UI it outputs 209 errors).
Doing this I came across a couple of issues that can be split into two groups of problems:
Problem 1
For problem 1 I've had a talk with Tim, and he thinks some reasonable fixes are:
Formula#add
conform toIndexedFormula#add
IndexedFormula#compareTerm
toIndexedFormula#compareTerms
We didn't go into depth of other inconsistencies, but it seems that we will have to break some APIs in any case if we want to fix this properly (currently we've used
@ts-ignore
to tell TypeScript to ignore them - but this won't fix the problem for projects that depend on this classes, as TypeScript will complain about inconsistent types here as well, which leads to a lot of unneccessary uses of ts-ignore).Problem 2
Problem 2 seems to come from the fact that many outputs from methods now uses the types described in the RDF/JS Data model specification (I'll just refer to them as RDF/JS types later in this text) instead of the corresponding rdflib ones, and this causes errors for projects such as Solid UI which has worked with rdflib types till now. This has been discussed earlier at #374 when @joepio worked on this earlier (and an even older thread at #137).
The data model types exported from rdflib (e.g. by doing
import { NamedNode } from 'rdflib'
) still refer to rdflib types, which causes type errors for projects such as Solid UI (one fix is to change all type references to the corresponding RDF/JS types, e.g. by doingimport { NamedNode } from 'rdflib/src/tf-types'
, but I think this is a very bad solution.One simple fix is to make sure that the types that TypeScript refers to are in fact referring to the RDF/JS types. But this will make it more difficult for people to use the extra functionality that is available in the rdflib types.
Now, Tim wants to make sure that types returned from rdflib are using the rdflib types (e.g. so that developers have access to some extra methods, such as
toNT
,doc
, andsite
).Since they are a superset, one theory of mine was to allow RDF/JS types as input for all relevant methods, but that they output rdflib types. The idea is that developers who want to work with RDF/JS can still do it (since rdflib types are a superset of RDF/JS types).
I started doing this work on a branch called fix-types-hybrid for those who want to review what I tried doing (note: it's incomplete code, so it won't run and there are bugs that I would've fixed before a proper PR).
When working on the branch I realized I was getting into a mess, and decided to raise these issues to get some feedback on how we might want to go about this.
Another challenge I found wrt types are unions that are different between RDF/JS and rdflib. E.g. for rdflib we have a type that describes which types we allow for many parameters that expect an object (as in subject-predicate-object):
While in RDF/JS it looks like the following:
Please don't mind the different names, the important difference here are the types that don't match in the unions; rdflib allows for
Collections
andEmpty
, while RDF/JS allows forTerm
. I think we might still get the concept to work (allow for RDF/JS types, output rdflib types), but I think it needs a bit of work.I also tried to work on another branch where the idea was to remove the RDF/JS types altogether, but I realized it was going to require a lot of work and I didn't want to revert the work of @joepio and @fletcher91 before having a discussion on this. For those interested in reviewing that work, it's available on branch fix-types-rdflib.
Hope to get feedback on this from @timbl, @RubenVerborgh, perhaps @dmitrizagidulin and @elf-pavlik who has been involved in these discussions earlier, as well as @joepio and @fletcher91 in case I forgot something in this issue, and @Vinnl who helped me with my thinking on TypeScript types earlier.
The text was updated successfully, but these errors were encountered: