-
Notifications
You must be signed in to change notification settings - Fork 482
TypeScript Definition Done! #167
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
Comments
Excellent! Thank you! Will include this in the docs on the website. |
Yea thanks! I wonder if this could be used in an editor like Visual Studio Code to get intellisense. |
We may need to revisit this in the future as our api surface evolves, but this seems a closed issue, thanks! |
Moved to new issue #268
|
How should I go about importing and using I've imported Loki using:
which compiles but is looking for the module I'd like to be able to do something like:
but can't seem to get the imports/exports right. I tried modifying the type definition file too. I'm new at using TypeScript and I know I haven't changed some of the code to use TypeScript features or the class fully. I'm just trying to get the imports to work first. If there are any docs you guys could point me to that would be helpful too. Thanks! |
I have not yet had the time to experiment that much with typescript or the definitions which @TeamworkGuy2 created for us, so I unfortunately can't provide any immediate help on this issue. The typescript definitions appear 9 months old so it is quite possible they are outdated. I would like at some point in the future to revisit this but have not had time. I'm not certain if he wants dissemination of this (and I just found so i'm not sure if its ready), but it would appear @TeamworkGuy2 is actively working on typescript wrapper for loki collections here : https://github.com/TeamworkGuy2/lokijs-collections (TWG2 if you would prefer I not link to that project, let me know and I will remove.) If anything it may give you some ideas while you are learning typescript with loki. |
I'm happy to have you link to it! Yes, the definition is somewhat out of date and I haven't had the interest in updating it since I've been working on the lokijs-collections project you linked to. Lokijs-collections is a work in progress, it's designed around meta-data schemas for each collection. These schemas containing primary key column names, non-nullable column names, data types, and a few other optional pieces that are used by new functions like DataCollection.addOrUpdate(). We use this meta-data to add constraints (such as uniqueness and auto-generated columns) to lokijs-collections without adding any additional API complexity to the developer besides setting up the initial schemas. The purpose of the library may not match your needs @OzzieOrca, but it does have some unit tests which contain code that uses the loki TypeScript definition file. You might be able to use it as a guide for using the typescript definition file in your project. You are right, Lokijs does require('fs') for the optional LokiFsAdapter (https://github.com/techfort/LokiJS/blob/master/src/lokijs.js#L1068). |
Fyi, @obeliskos and @OzzieOrca, I updated lokijs.d.ts type definition over on DefinitelyTyped to latest loki.js v1.3.16. |
That's awesome, thank you! Interesting project as well :) |
Typings are located here, although they don't seem to be up-to-date.
|
@thasmo is not updated and is missing a few thing there. I don't see updateWhere and there's conflicts and a few methods |
@thasmo, @nmocruz - [email protected] definition just got merged to definitely typed (pull: DefinitelyTyped/DefinitelyTyped#21747, commit: DefinitelyTyped/DefinitelyTyped@766089f). Should auto update to npm in a day or two. |
@TeamworkGuy2 Thanks for your work on this, spending so much time! I'll definitely have a look. |
@TeamworkGuy2 Very good work! Just one question: Does the LokiQuery works with nested properties? |
@Viatorus No, although I left EDIT:
Let's create a tripled nested version of LokiQuery: type PartialModelNested<E, T> = { [P in keyof E]?:
{ [P2 in keyof E[P]]?:
{ [P3 in keyof E[P][P2]]?: any }
} | T
};
type LokiQuery<E> = PartialModelNested<E & { $and: any; $or: any }, { [Y in keyof LokiOps]?: any }>;
var query: LokiQuery<{ name: string; posts: { id: number; text: string }[] }> = {
name: "abc",
posts: { ...
}; The problem quickly becomes apparent when we try to write a query using our new type. |
Also branchresultset is defining all parameters as optionals
Em 05/12/2017 12:41, "Viatorus" <[email protected]> escreveu:
… Reopened #167 <#167>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#167 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA5o5V2Ugc0mF5NNrvgHgAPjKG_3xURlks5s9ToIgaJpZM4E_EUM>
.
|
@TeamworkGuy2 thank you for your explanation. What you wanted can maybe implement this way: type R<T> = {
[P in keyof T]: R<T[P]>;
}
interface Foo {
bar: {
baz: {
name: string;
}
};
}
let r: R<Foo>;
r.bar.baz.name = "123"; But this does not help here. let query = {"bar.baz.name": 123} Currently, typescript cannot handle this in an easy way. (There are some proposals like this one). What I have done today is the following: /**
* E = the data type
* N = the nested properties
*/
class Collection<E, N> {
public data(): E[];
public find(LokiQuery<E & N>);
}
interface Foo {
bar: {
baz: {
name: string;
}
};
}
let coll = new Collection<Foo, {"bar.baz.name": string}>
coll.find({"bar.baz.name": "test"}); |
@Viatorus good stuff, thanks for sharing! That's why I made all the interfaces global so other people can extend them to work best in their own situations. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Wasn't sure where to post this, it's not an issue, just wanted to let those who use LokiJS know.
For those of you who use or might be interested in TypeScript, there's a newly added TypeScript definition for LokiJS over at the DefinitelyTyped repository: https://github.com/borisyankov/DefinitelyTyped/tree/master/lokijs.
The text was updated successfully, but these errors were encountered: