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

improve type definition of from(obj: object) #94

Merged
merged 1 commit into from
May 12, 2022

Conversation

Neuroboy23
Copy link
Contributor

@Neuroboy23 Neuroboy23 commented Apr 29, 2022

Prior to this change, using Enumerable.from(...) on a simple map object with typed keys would lose the key type. This may be intentional due to edge cases with which I am unfamiliar. I am submitting this PR in hopes that is not the case.

type KeyType = "foo" | "bar" | "baz";

const input: Record<KeyType, number> = {
    foo: 1,
    bar: 2,
    baz: 3
};

const output = Enumerable.from(input)
    .toObject(
        e => e.key,
        e => e.value * 10
    );
    
// result:  output is a `Record<string, number>`

// desired: output is a `Record<KeyType, number>`

@mihaifm mihaifm merged commit a5ca60b into mihaifm:master May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants