-
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
TypeScript declaration files #251
Conversation
Hi @SnappyCroissant and @pocesar.
@oskarhane could you please review as well? and share your general feeling about this? |
I'm positive, this is a good step. |
@lutovich looks good! I will eventually help with the generics (by using your own created interfaces to create safe code through the driver), but that's the cherry on top, the base definitions LGTM EDIT: for example, when using subscribe, you'd want to have a |
@pocesar thanks for the review! const result: Result = session.run("RETURN 42, "42", ["42"]");
const record: Record = result.records[0];
const value1: number = record.get(0);
const value2: string = record.get(1);
const value3: string[] = record.get(2); Am I missing something? |
in TS you can have union types, like tx.run<Partial<Type1 & Type2 & Type3>>().records[0].// has members of Type1, 2 and 3, but if you use |, you can refine the type by checking for it's members besides writing less code and not having to rely on variables, it makes composition easier (even more when dealing with async / promises code), so when you're writing wrappers around neo4j driver, and consuming in your code, it becomes much more evident, since you don't need to check the code to understand what will come out of the function / method (talking consumers / team members here) check |
Everything within my understanding looks good. Discriminated Unions are a bit above my level of understanding but I'm educating myself now! |
Nice, thanks for review! |
Im counting on you @lutovich |
Covered All Externals I think. First time writing Type Definitions so anyone else feel free to take over and do a better job.
Removed a Comma that had wound up in a js file when I was first figuring everything out.
mv command left over can't use types as variables add some missing stuff, fix implicitAny errors can't use types for vars noImplicitAny and optional parameters type safety for session.run results needs typeof in const declaration for it to work result summary members unprotect members
there's no public accessors in records member
_fields is wrong, it should be an array of T
Commit moves all type script definition files from `lib` folder to a dedicated folder `types` located in the project root. This is cleaner because `lib` contains generated sources.
Changes include: * removed definitions for non-public classes and functions * used interfaces as much as possible to define API shapes * added super-interface `StatementRunner` for `Session` and `Transaction` to define signature of `#run()` is one place * added license headers * applied default IntelliJ code formatter
This commit adds a first simple test for transaction class TypeScript definitions. Actual test code is not executed, it is just compiled using the TypeScript compiler to verify correctness of types. Also added npm script to run TS definition tests `test-types`. More tests will be added in subsequent commits.
And updated corresponding npm script: `run-ts-declaration-tests`. It is now part of gulp's `test` task.
353380c
to
0a52c19
Compare
@lutovich please don't forget to bump version and release it at npm ❤️ |
@cojack these should be released with 1.4.0-beta01 early next week. Pre-release versions are available with |
Pre-release version 1.4.0-beta01 is now available on npm, please feel free to try it out, give feedback and contribute. |
@lutovich I had a problem with explicitly property type definition. import * as Neo4j from 'neo4j-driver';
// stuff
private driver: Neo4j.v1.Driver; Typescript said:
So I resigned with type annotation for this field, but I guess it should works. |
@cojack non-default declaration does not export import Neo4j from 'neo4j-driver';
// stuff
private driver: Neo4j.Driver; I'm not quite sure if we need to export all types from |
@lutovich nope, it doesn't not work with your proposal. Anyway, doesn't have to 👍 |
Added TypeScript declaration files for all public driver APIs. These should make it easier to use driver in TypeScript projects.
PR is heavily based on #183. Thanks for contribution @SnappyCroissant and @pocesar.
Closed #77
Not ready for merge: all declaration files should be covered with tests. Currently on
transaction.d.ts
is.