Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine fails on large unions with object API but works via multiple arguments API #531

Closed
7rulnik opened this issue Oct 6, 2021 · 4 comments
Labels
bug Something isn't working typings Typescript public type definitions issues

Comments

@7rulnik
Copy link

7rulnik commented Oct 6, 2021

Missing/Incorrect APIs

The example below fails with Type instantiation is excessively deep and possibly infinite.(2589).

It's obvious that this problem is related to Currency variations. It works with 14 elements, but not more. I also tried 4.5.0-beta with Tail-Recursion Elimination but the result is the same.

Also, it could be workarounded via multiple arguments, but it leads to more verbose code.

import { createStore, combine } from 'effector';

type Currency = 'usd' | 'eur' | 'cny' | 'uah' | 'byn' | 'thb' | 'rub' | 'azn' | 'kzt' | 'kgs' | 'uzs' | 'tzs' | 'kes' | 'zar' | 'ron' | 'mdl' | 'ils' | 'inr' | 'pln' | 'chf' | 'gbp';


const initialValue = 'usd' as Currency;

const $currency = createStore<Currency>(initialValue)

type AutosearchTrigger = {
  currency: Currency;
};

// Will fail with «Type instantiation is excessively deep and possibly infinite.»
const $autosearchTrigger = combine<AutosearchTrigger>({
  currency: $currency,
});


const $autosearchTriggerViaTuple = combine<Currency, AutosearchTrigger>($currency, (currency) => ({
  currency
}));

Playground Link: Provided

Relevant documentation

combine(...stores, fn) works
combine({ A, B, C }, fn?) doesn't work

@7rulnik 7rulnik added the typings Typescript public type definitions issues label Oct 6, 2021
@sergeysova
Copy link
Member

sergeysova commented Oct 14, 2021

It is better not to pass generic arguments to combine.
Try to remove them and left all work to typescript.

But without generics looks very interesting.

Thank you for your report!

@sergeysova sergeysova added the bug Something isn't working label Oct 14, 2021
@sergeysova
Copy link
Member

Similar problem: microsoft/TypeScript#30188 (comment)

sergeysova added a commit that referenced this issue Oct 15, 2021
zerobias added a commit that referenced this issue Oct 21, 2021
@zerobias zerobias added this to the effector 22.2.0 milestone Nov 24, 2021
@zerobias
Copy link
Member

zerobias commented Dec 8, 2021

Fix will be published in the next minor release but looks like typescript 4.5.0 already added support for that case on their side

@zerobias zerobias closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typings Typescript public type definitions issues
Projects
None yet
Development

No branches or pull requests

3 participants