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

Type definition errors #369

Closed
Vinnl opened this issue Oct 22, 2019 · 9 comments
Closed

Type definition errors #369

Vinnl opened this issue Oct 22, 2019 · 9 comments
Assignees

Comments

@Vinnl
Copy link
Collaborator

Vinnl commented Oct 22, 2019

Since #356, rdflib ships a TypeScript type defintion file index.d.ts that refers to other files in the same directory (i.e. it contains statements like import BlankNode from './blank-node'; import Collection from './collection'; // etc.), but those files are not generated. This results in TypeScript compilation errors for downstream projects:

node_modules/rdflib/lib/index.d.ts(1,23): error TS7016: Could not find a declaration file for module './blank-node'. '/home/travis/build/solid/solid-ui/node_modules/rdflib/lib/blank-node.js' implicitly has an 'any' type.

node_modules/rdflib/lib/index.d.ts(2,24): error TS7016: Could not find a declaration file for module './collection'. '/home/travis/build/solid/solid-ui/node_modules/rdflib/lib/collection.js' implicitly has an 'any' type.

# etc.

/cc @joepio

@joepio
Copy link
Collaborator

joepio commented Oct 22, 2019

#363 should fix this, includes many types. I'll modify the .npmignore in a future PR.

Vinnl added a commit that referenced this issue Oct 22, 2019
@Vinnl
Copy link
Collaborator Author

Vinnl commented Oct 22, 2019

Make sure that it's .npmignore, not .gitignore :) git revert c097d1a4797a22724e13f178461377a608637e8e should be sufficient.

@joepio
Copy link
Collaborator

joepio commented Oct 22, 2019

Gotcha!

@mrkvon
Copy link

mrkvon commented Feb 2, 2020

When installing rdflib v1.0.6 in a typescript project and writing import rdf from 'rdflib', I get:

error TS7016: Could not find a declaration file for module 'rdflib'. '[path/to]/node_modules/rdflib/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/rdflib` if it exists or add a new declaration (.d.ts) file containing `declare module 'rdflib';`

Since the @types/rdflib was deprecated, the available options are to declare the module manually (no types) or install @types/[email protected] (may be out of date).

Are there any other solutions available at the moment?

@Vinnl
Copy link
Collaborator Author

Vinnl commented Feb 2, 2020

@mrkvon They shouldn't have been deprecated yet, see DefinitelyTyped/DefinitelyTyped#42044

You can either attempt to install an earlier version of those type definitions, wait until my PR at DT has been accepted, or use the prerelease version of rdflib (npm install rdflib@next) at your own risk.

@ludwigschub
Copy link
Contributor

ludwigschub commented Oct 16, 2020

is this fixed yet?
I get the same errors when trying to compile a package that uses rdflib v1.3.1 as a dependency

@Vinnl
Copy link
Collaborator Author

Vinnl commented Oct 19, 2020

@ludwigschubi yes, this should have been fixed - the release with TS support was 1.0.7 IIRC. I guess it's probably better for you to report a separate bug that can focus wholly on your issue - I'll close this one.

@Vinnl Vinnl closed this as completed Oct 19, 2020
@pduchesne
Copy link
Contributor

This is still a problem if your TS project has "noImplicitAny=true", because plain js files (e.g. query.js) do not get transpiled to .d.ts .
Here's a PR that works for me : #513 .

@Jeronimo59
Copy link

Jeronimo59 commented Oct 25, 2023

Hello,

I am trying to use rdflib (version 2.2.32) with Typescript, and I cannot get it to work.
Could that be the same type declaration issue ?

On the other hand, VS Code Intellisense does recognize rdf reference, and points to index.d.ts when I "go to definition"

import rdf from 'rdflib';

const store = rdf.graph();  => throws 'Cannot read properties of undefined (reading \'graph\')'

I tried setting "noImplicitAny" to 'false' in tsconfig.json, but it didn't solve the issue.

Apologies in advance if I am missing the obvious...

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

No branches or pull requests

6 participants