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

[Question] Question about random generation results for tuples #600

Closed
kakasoo opened this issue Apr 24, 2023 · 5 comments
Closed

[Question] Question about random generation results for tuples #600

kakasoo opened this issue Apr 24, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@kakasoo
Copy link
Contributor

kakasoo commented Apr 24, 2023

The typia.random method generates tuples in the correct order when they are received, but inference at the type level is not. I don't know if this is a bug or a limitation of the type system, so I leave a question for now.

    it('typia `random` function generate tuple', async () => {
        type ZERO_TO_SIX_TUPLE = [0, 1, 2, 3, 4, 5, 6];

        const values = typia.random<ZERO_TO_SIX_TUPLE>(); // this type is `(0 | 1 | 2 | 3 | 4 | 5 | 6)[]`

        expect(values.at(0) === 0).toBeTruthy(); // no problem
        expect(values.at(1) === 1).toBeTruthy(); // no problem
        expect(values.at(2) === 2).toBeTruthy(); // no problem
        expect(values.at(3) === 3).toBeTruthy(); // no problem
        expect(values.at(4) === 4).toBeTruthy(); // no problem
        expect(values.at(5) === 5).toBeTruthy(); // no problem
        expect(values.at(6) === 6).toBeTruthy(); // no problem
    });

I thought that the value of values should be [0, 1, 2, 3, 4, 5, 6], and the type inference should be the same [0, 1, 2, 3, 4, 5, 6] in the following situations. Because the union type tuple consisting of numbers from 0 to 6, and the tuple where each number and the number have a fixed index, are different.
In summary, '(0 | 1 | 2 | 3 | 4 | 5 | 6)[]' and [0, 1, 2, 3, 4, 5, 6] are different.

Thank you always for creating such a wonderful library.

@samchon
Copy link
Owner

samchon commented Apr 24, 2023

This problem is caused by Primitive type.

What about fix the bug and send a PR?

https://github.com/samchon/typia/blob/master/src/Primitive.ts

@samchon samchon self-assigned this Apr 24, 2023
@samchon samchon added the bug Something isn't working label Apr 24, 2023
@kakasoo
Copy link
Contributor Author

kakasoo commented Apr 24, 2023

OK, I'll try it today.

kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
@kakasoo
Copy link
Contributor Author

kakasoo commented Apr 24, 2023

For each element of the tuple, _Primivite not applied #600

If a tuple has a rapper object, _Primitive was not applied because it makes sense to infer it as it is.

kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
- There was a much simpler way.
kakasoo added a commit to kakasoo/typia that referenced this issue Apr 24, 2023
samchon pushed a commit that referenced this issue Apr 24, 2023
* fix tuple inference in the _Primitive type #600

* Processing for tuples and not #600

* For each element of the tuple, _Primivite not applied #600

* Define a Spread type to reduce type depth #600

* Just list each element #600

- There was a much simpler way.

* fix : _Primitive applied #600
@kakasoo kakasoo closed this as completed Apr 24, 2023
@kakasoo
Copy link
Contributor Author

kakasoo commented Apr 24, 2023

Summary.

I decided to separate the cases of tuples from the _Primitive type and apply _Primitive to each tuple element. There was an error in the test code related to 'Atomic Class', but according to Samchon, this is a problem related to assertParse method, so I will send PR and close the issue.
Thank you for giving me an opportunity to contribute.

@samchon
Copy link
Owner

samchon commented Apr 24, 2023

@kakasoo Be fixed. Upgrade to v3.7.8 please.

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

No branches or pull requests

2 participants