Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-13-2019 12:25 AM
I have used the neo4j-driver in the past but now want to use it in a project written in Typescript. I had expected that I could just get the type definityions by using @types/neo4j-driver like with so many other libraries. Searching the web I have not found anything helpful or even current, this also does not seem to be documented in the official driver docs ( or at least I can't find it). I am surprised it doesn't seem to have come up as a topic here (apologies if it has and I just can't find it - I have looked).
How/where do I get the types for the javascript neo4j-driver to use in a Typescript project?
Solved! Go to Solution.
09-16-2019 11:19 AM
The type definitions are distributed with the neo4j-driver package and are not in the DefinitelyTyped repo. You can find the type definitions here and can use them like this:
import neo4j from "neo4j-driver";
const driver: neo4j.Driver = neo4j.driver("bolt://localhost");
const session: neo4j.Session = driver.session();
09-16-2019 11:19 AM
The type definitions are distributed with the neo4j-driver package and are not in the DefinitelyTyped repo. You can find the type definitions here and can use them like this:
import neo4j from "neo4j-driver";
const driver: neo4j.Driver = neo4j.driver("bolt://localhost");
const session: neo4j.Session = driver.session();
11-22-2019 02:30 PM
To reopen this topic:
If you wish you can also check out Drivine - a community TypeScript driver with a sweet-spot level of abstraction.
It is designed to scale to hundreds/thousands of txns per second and:
11-04-2020 10:41 AM
While developing some neo4j stuff in a typescript project i run into a related problem. I don't use DefinitelyTyped repo. I found a quick fix, but I thought it may helps some others, and maybe could fix it or explains me why it happened.
import neo4j from 'neo4j-driver';
const driver: neo4j.Driver = neo4j.driver("bolt://localhost");
const session: neo4j.Session = driver.session();
would serve me (in visual code) a "Cannot find namespace neo4j"
However the following works
import neo4j from 'neo4j-driver';
const driver: typeof neo4j.Driver = neo4j.driver("bolt://localhost");
const session: typeof neo4j.Session = driver.session();
works just fine.
I am using typescript "^3.2" and neo4j-driver "^4.1.2"
09-21-2021 04:33 AM
as per your suggestion, there are no errors if I use const session: typeof neo4j.Session = driver.session();. But session object does not have a close method. it has only two properties read and write. How to fix this issue?
04-01-2022 11:30 AM
Alternatively, you can also import those specific types using an import type
statement. There's more information here in the Typescript's 3.8 documentation.
import neo4j from 'neo4j-driver';
import type { Driver, Session } from 'neo4j-driver';
const driver: Driver = neo4j.driver("bolt://localhost");
const session: Session = driver.session();
All the sessions of the conference are now available online