Coder Social home page Coder Social logo

Comments (4)

laat avatar laat commented on June 5, 2024

Is the problem that type cannot be inferred here?

declare function unionArg(
  x: { type: 'FOO' } | { type: 'BAR'; x: number } | (() => void)
): void;

// type is any when hovering in vscode?
unionArg({type: })

I do not think this is an issue with redux-thunk. It is a usability issue with typescript, because the types are correct.

image

from redux-thunk.

zqran avatar zqran commented on June 5, 2024

@laat The key point is not that the type of type property is any, but when you typing the type attribute, there is no type hint.

declare function unionArg(
  x: { type: 'FOO' } | { type: 'BAR'; x: number } | (() => void)
): void;

// type is any when hovering in vscode?
unionArg({type: })

However, the code you provided will prompt you when you typing the type attribute.

from redux-thunk.

laat avatar laat commented on June 5, 2024

I see, yes I can reproduce it. It's strange that it is aware of the types, but unable to complete.

image

from redux-thunk.

markerikson avatar markerikson commented on June 5, 2024

I spent some time today playing around with this. Loosely put, if I try rearranging the overloads, I can get correct inference for type here, but some of our other typetests fail.

This is an edge case anyway. We generally expect that A) the thunk middleware will not be typed to be restricted to a specific set of dispatchable actions (per https://redux.js.org/usage/usage-with-typescript#avoid-action-type-unions ), and B) users won't normally be hand-writing a type field in a plain action object as they dispatch because they'll be using action creators.

Given that, I don't think this is something we're going to fix, unless someone else comes up with a way to rearrange the types without breaking things.

from redux-thunk.

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.