Git Product home page Git Product logo

Comments (5)

SamChou19815 avatar SamChou19815 commented on June 13, 2024 1

I have a smaller repro here.

from flow.

mwiencek avatar mwiencek commented on June 13, 2024

I don't have to expand it within the set type parameters; it also works if expand it in the KeyType2 definition:

-type KeyType2<+T, +K1> = KeyType<PropType<T, K1>>;
+type KeyType2<+T, +K1> = PropType<T, K1> extends $ReadOnlyArray<mixed> ? number : PropType<T, K1> extends {...} ? $Keys<PropType<T, K1>> : empty;

Edit: Also, weirdly, if I revert all the inlining and just do ('year': KeyType2<DatePeriods, 0>);, then that type-checks fine. So it works in some cases, but not in the set function.

from flow.

SamChou19815 avatar SamChou19815 commented on June 13, 2024

The behavior seems expected to me. number is coming from KeyType<DatePeriods>. Conditional type is order sensitive. If you switch the order of two conditions in KeyType, it would work

from flow.

mwiencek avatar mwiencek commented on June 13, 2024

@SamChou19815 Thanks for the pointer, but not sure I follow: in the expanded version the order of the conditions is the same, isn't it?

The error message suggests that K2: KeyType2<T, K1> should be number, but K1 is KeyType<DatePeriods>, which is also number. Indeed this works fine:

type KeyType2<+T, +K1> = KeyType<PropType<T, K1>>;

('year': KeyType2<DatePeriods, KeyType<DatePeriods>>);

from flow.

mwiencek avatar mwiencek commented on June 13, 2024

@SamChou19815 Thanks for the fix!

from flow.

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.