Skip to content
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

Typescript declaration file (documentation and static typing) #179

Closed

Conversation

Neur0mante
Copy link
Contributor

This is the first draft of a declaration file in typescript that regroups all the documentations for the public items available when importing $rdf, and also defines the types required and returned from the available functions and methods.
This change will only consist on adding the index.d.ts file in the main folder and the
"types": "./index.d.ts"
line in the package.json, there is no need to include a typescript library in the project for this to work.

In most IDEs when using typescript this provides strong, statically typed checks at compile time, aside from more fine grained documentation.
In vscode and visualstudio the documentations and type informations will also be available in .js files.
screenshot_7
screenshot_6

This approach will keep the documentation separate so it can be distributed aside the babeled or minified version and still work.
I could publish this in the definitelyTyped repository if you do not wish to have it inside your project, but that will require some more steps on the user's side while this way is much cleaner.

I have introduced a couple of alias types

 export type LiteralTypes = string | Date | number | boolean
 export type Nodeable = LiteralTypes | Node | CollectionArray
 interface CollectionArray extends Array<Nodeable> { } 

because some methods (statementsMatching and similar) were becoming too verbose to read. Nodeable just indicates things that are accepted from the Node.fromValue() (it also allows for proper checking of the circular definition, as Nodeable can be an array of Nodeable)
I haven't been too strict on the typing of most methods cause that would require a lot of manual inspection, and if I'm wrong the method would not work in typescript.
Also, tagging class members and methods as private will surely improve the code usability through intellsense but again I'm not completely sure which ones are only intended for internal usage.

@Neur0mante Neur0mante force-pushed the declaration-and-documentation branch from 5415106 to 47e79ac Compare March 28, 2017 12:23
@woutersl
Copy link

Hi, I am using rdflib.js in Typescript, thanks for the great work.
Currently I have to provide my own type definitions to make it work though. The integration of this PR would be a great help.

Would it be possible to clarify what holds back the integration of this proposal and, if appropriate, what should be done to facilitate it?
Thanks!

@willemneal
Copy link

Is this not ready to merge?

@kjetilk
Copy link
Member

kjetilk commented Sep 27, 2018

Interesting! I'm not the right person to evaluate, but I'm adding @RubenVerborgh as reviewer.

@RubenVerborgh RubenVerborgh requested review from timbl and removed request for RubenVerborgh September 28, 2018 07:19
@RubenVerborgh
Copy link
Member

Me neither; the person who knows the API best is @timbl.

I suspect the API will have changed since this PR.

@RubenVerborgh
Copy link
Member

Actually, I think the rdflib.js API is changing too fast at the moment to commit to TypeScript, definitely without tests. I would suggest to put this into https://github.com/DefinitelyTyped/DefinitelyTyped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants