GithubHelp home page GithubHelp logo

Comments (3)

posva avatar posva commented on May 10, 2024

I pushed a new test at 40d0996 but I remember it wasn't possible to type this and the first argument at the same time. On top of that, this can be typed with other getters while the argument cannot.

In my tests, state has type any, so not sure how you manage to get that one but I don't think there is a way to support both this and the argument types. If you want to give it a try or TS end up somehow supporting it, feel free to give it a try and open a pull request

from pinia.

MartinMalinda avatar MartinMalinda commented on May 10, 2024

I tried to do a quick hack of G extends Record<string, (this: { state: S } & A & G, state: S) => any> but it doesn't work well, maybe because G references itself there. It is indeed strange how this stops being inferred once an argument type is declared.

from pinia.

posva avatar posva commented on May 10, 2024

I gave this a try to at least have the state as the first parameter but couldn't make all the existing type tests pass. It's on https://github.com/posva/pinia/tree/types/getters-state if anyone can help.

Ideally, one should be able to have an automatically inferred type for a getter like this:

double: state => state.count * 2

from pinia.

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.