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

Strange return type of DeepImmutable and Immutable for ReadonlyArray and ReadonlyMap #65

Closed
the-dr-lazy opened this issue May 27, 2019 · 0 comments · Fixed by #80
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@the-dr-lazy
Copy link
Owner

Summary

By nested DeepImmutable or directly passing ReadonlyArray and ReadonlyMap to DeepImmutable and Immutable types results in DeepImmutableObject<ReadonlyArray> and DeepImmutableObject<ReadonlyMap> which should be neutralized by the type itself.

Steps to reproduce

For ReadonlyArray:

type A = DeepImmutable<DeepImmutable<string[]>>

For ReadonlyMap:

type B = DeepImmutable<DeepImmutable<Map<'key', 'value'>>>

Expected result(s)

For ReadonlyArray:

type A = DeepImmutableArray<string>

For ReadonlyMap:

type B = DeepImmutableMap<'key', 'value'>

Actual result(s)

For ReadonlyArray:

type A = {
    readonly [x: number]: string;
    readonly length: number;
    readonly toString: () => string;
    readonly toLocaleString: () => string;
    readonly concat: {
        (...items: ConcatArray<string>[]): string[];
        (...items: (string | ConcatArray<string>)[]): string[];
    };
    ... 16 more ...;
    readonly includes: (searchElement: string, fromIndex?: number | undefined) => boolean;
}

For ReadonlyMap:

type B = {
    readonly forEach: (callbackfn: (value: "b", key: "a", map: ReadonlyMap<"a", "b">) => void, thisArg?: any) => void;
    readonly get: (key: "a") => "b" | undefined;
    readonly has: (key: "a") => boolean;
    readonly size: number;
    readonly entries: () => IterableIterator<...>;
    readonly keys: () => IterableIterator<...>;
    readonly values: () => IterableIterator<...>;
}

Solution

Add conditions to check ReadonlyArray and ReadonlyMap in DeepImmutable and Immutable types.

@the-dr-lazy the-dr-lazy added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels May 27, 2019
@the-dr-lazy the-dr-lazy added this to the v1.4.1 milestone May 27, 2019
@the-dr-lazy the-dr-lazy self-assigned this May 30, 2019
@the-dr-lazy the-dr-lazy removed good first issue Good for newcomers help wanted Extra attention is needed labels May 30, 2019
the-dr-lazy pushed a commit that referenced this issue Jun 9, 2019
## [1.4.1](v1.4.0...v1.4.1) (2019-06-09)

### Bug Fixes

* infer return type of reducer from return type of handlers ([6b6edaa](6b6edaa)), closes [#55](#55)
* nested DeepImmutable and Immutable types neutralization ([d3f9a1a](d3f9a1a)), closes [#65](#65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant