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

Add stricter Object.fromEntries for constructing from const tuples #50203

Closed
wants to merge 4 commits into from

Commits on Aug 6, 2022

  1. Add stricter Object.fromEntries for constructing from const tuples

    `Object.fromEntries` as is declared today resulted in a loss of key names and a unionization of all values, or a complete loss of information and type of `any`. 
    This change makes it so that it is possible to create strict objects from const tuples.
    
    ```ts
    const obj1 = Object.fromEntries([
      ['1', 2],
      ['3', 4],
    ] as const)
    
    // now results in an object of type: {1: 2, 3: 4}, previously { [k: string]: 2 | 4 }
    
    const obj2 = Object.fromEntries([
      ['1', 2],
      ['3', '4'],
    ] as const)
    
    // now results in an object of type: {1: 2, 3: '4'}, previously any
    ```
    niieani committed Aug 6, 2022
    Configuration menu
    Copy the full SHA
    898810a View commit details
    Browse the repository at this point in the history

Commits on Aug 18, 2022

  1. Target only fixed length tuples

    Only create strict types from const tuples, since we cannot guarantee the existence of any key in an iterable.
    niieani committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    7545c59 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    bef1f02 View commit details
    Browse the repository at this point in the history
  3. Fix signature

    niieani committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    5f38d95 View commit details
    Browse the repository at this point in the history