Giter Site home page Giter Site logo

Typescript support about gstore-node HOT 12 CLOSED

nexussmart avatar nexussmart commented on May 25, 2024 2
Typescript support

from gstore-node.

Comments (12)

kirillgroshkov avatar kirillgroshkov commented on May 25, 2024 3

We also need TS support. Well, it serves as documentation, it allows to use IntelliSense, and fits well in the project that is already using Typescript everywhere.

I can see that Google in their different APIs are moving faster and faster with adopting Typescript and providing typings inside libraries (Firebase, for example, many others too, but not datastore itself yet).

If to narrow down to 1 argument:

It serves as documentation, sometimes better than documentation itself.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024 1

Yes that might be a solution. Just writing the type definitions files 😄 I was thinking in converting the whole project from js to Typescript but might not be necessary. I will give it a thought.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024 1

Hello,
I just made a release (v4.1.0) with Typescript support. Let me know if it works for you 👍

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hello,
Although this would be a nice feature, this is not currently planned in future releases. I guess you are mainly interested in getting all the typings for your project?

It would be nice to know what is the interest for Typescript support. Let's leave this issue opened and find out 😄

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Ok I take note. I am currently finishing a big feature (cache mechanism) for the next release (v3.0.0)
Typescript might then be a next target.

from gstore-node.

kirillgroshkov avatar kirillgroshkov commented on May 25, 2024

Sounds good! Good luck with 3.0!

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hello..
Could you point me to a few good node library that you use that are made in Typescript? So I can have a look at how they package and expose their lib.
thanks!

from gstore-node.

LogansUA avatar LogansUA commented on May 25, 2024

@sebelga I'm also interested in typescript types.

Here's repository for typescript types.

For examples you can check the @types/express or @types/node

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hi @LogansUA thanks but I was referring to NodeJS libraries you are using in your projects done in Typescript. So I can have a look at how they expose their bundles. (both in es6 and Typescript format). 👍

from gstore-node.

LogansUA avatar LogansUA commented on May 25, 2024

Well, I'm now using express, dotenv, ramda, stripe, winston etc. in my TS project with their typescript types

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hello,
I finished writing the typings for gstore-node. I haven't published it yet as I would like if someone could test it in a actual Typescript project. I hope I haven't forgot anything 😄

@LogansUA @nexussmart @kirillgroshkov could one of you test this inside your project?

Just clone the "feature/#89-typescript-definitions" branch and replace the content in the node_modules/gstore-node folder.

This is how to add the Types for a User Model

type UserTypes = {
    userName: string;
    email: string;
    age?: number; // optional
    tags?: string[]; // optional
    birthday?: Date; // optional
}

// Strict typings (not other properties allowed than the ones on Schema)
// ----------------------------------------------------------------------------------
const schema = new Schema<UserTypes>({
    userName: { type: 'string' },
    email: { type: 'string' },
    age: { type: 'int', optional: true },
    tags: { type: 'array', optional: true },
    birthday: { type: 'datetime', optional: true },
    unknownNotAllowed: {} // this should give a ts error
});

const User = gstore.model<UserTypes>('User', schema);

// Strict typings + other properties allowed (explicitOnly: false)
// ----------------------------------------------------------------------------------
const schema = new Schema<UserTypes>({
    userName: { type: 'string' },
    email: { type: 'string' },
    age: { type: 'int', optional: true },
    tags: { type: 'array', optional: true },
    birthday: { type: 'datetime', optional: true },
    unknownNotAllowed: {} // this should give a ts error
}, { explicitOnly: false });

// Allow "other" properties on the entities
const User = gstore.model<UserTypes & {[propName: string]: any}>('User', schema);

// No Tyings on Schemas (backward compatible)
// ----------------------------------------------------------------------------------
const schema = new Schema({
    userName: { type: 'string' },
    email: {},
    age: {},
    tags: {},
    birthday: {},
    unknownAllowed: {} // this should *not* give a ts error
}, { explicitOnly: false });

const User = gstore.model('User', schema);

from gstore-node.

kirillgroshkov avatar kirillgroshkov commented on May 25, 2024

Great, thanks! I'll get back when we actually try and start using it. But good to know that we have types now!

from gstore-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.