Code Monkey home page Code Monkey logo

Comments (8)

markerikson avatar markerikson commented on June 7, 2024 5

Went ahead and filed https://youtrack.jetbrains.com/issue/WEB-42559 .

I'll go ahead and close the issue, since this doesn't appear to be a problem in RTK itself. Thanks for reporting it, though!

from rtk-github-issues-example.

markerikson avatar markerikson commented on June 7, 2024

That doesn't sound right. Can you post the code that generated the displayRepo action creator?

Erm. Wait, this is on the example repo.

Where are you seeing that issue, specifically? Is it just from cloning the repo, in one of the sandboxes, or something else?

FWIW, if I open the repo as of its final commit and hover over displayRepo, I don't see any errors, and I see this type signature:

image

from rtk-github-issues-example.

RobertMenke avatar RobertMenke commented on June 7, 2024

Hey, this is from cloning the repo and then opening it up in IntelliJ. After clicking into the function IntelliJ does seem to think that the type definition should match

    displayRepo(state, action: PayloadAction<CurrentRepo>) {
      const { org, repo } = action.payload
      state.org = org
      state.repo = repo
    },

After looking into the types a bit more I believe this actually may be an IntelliJ bug.

declare type CaseReducerActions<CaseReducers extends SliceCaseReducerDefinitions<any, any>> = {
    [Type in keyof CaseReducers]: IfIsCaseReducerWithPrepare<CaseReducers[Type], ActionCreatorWithPreparedPayload<PrepareActionForReducer<CaseReducers[Type]>>, IfIsReducerFunctionWithoutAction<CaseReducers[Type], ActionCreatorWithoutPayload, PayloadActionCreator<PayloadForReducer<CaseReducers[Type]>>>>;
};

^^ The above doesn't seem to have any reference to state as an expected parameter, although the types are quite hard to parse at first glance :).

from rtk-github-issues-example.

markerikson avatar markerikson commented on June 7, 2024

The above doesn't seem to have any reference to state as an expected parameter, although the types are quite hard to parse at first glance :).

Hah, no kidding :) I'm the maintainer, and I barely understand them! :) I'm grateful that there's some TS experts in the Redux community who have been able to put those together for us.

The action creators definitely do not have any references to the state, either as an argument or a related type. They do reuse the type of the action argument for the reducer. For this example, since action is a PayloadAction<CurrentRepo>, the action creator knows that it should return {type: "issuesDisplay/displayRepo, payload: CurrentRepo}. It also will have a signature of (payload: CurrentRepo) => PayloadAction<CurrentRepo>.

from rtk-github-issues-example.

markerikson avatar markerikson commented on June 7, 2024

FWIW, I just opened up that same project in WebStorm 2019.1, and the type appears correct there too: waitasec what is that?

image

No. No, there's definitely not supposed to be a state argument for displayRepo. Wut.

I wonder if it's somehow mixing up the action creators and the reducers? Especially since it's labeling the arguments (state, action), and not (payload) like the action creator should have.

from rtk-github-issues-example.

RobertMenke avatar RobertMenke commented on June 7, 2024

Hmm yes looks like a Jetbrains bug... sigh I don’t think they use LSP for typescript. Thank you for looking into this one! I may open an issue in their issue tracker and reference this issue.

from rtk-github-issues-example.

markerikson avatar markerikson commented on June 7, 2024

Yeah, I was just about to do that, actually :)

from rtk-github-issues-example.

luokuning avatar luokuning commented on June 7, 2024

Went ahead and filed https://youtrack.jetbrains.com/issue/WEB-42559 .

I'll go ahead and close the issue, since this doesn't appear to be a problem in RTK itself. Thanks for reporting it, though!

I just vote for the request on youtrack.

from rtk-github-issues-example.

Related Issues (9)

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.