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

[core/public/deepFreeze] fix recursive type for better array support #22904

Merged
merged 1 commit into from
Sep 11, 2018

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Sep 10, 2018

The deepFreeze() function used by core.injectedMetadata uses a recursive type definition to indicate that all of the child types within the passed argument become readonly, which works fine for objects but represents arrays as objects instead of using the ReadonlyArray<> type.

This PR fixes the type definition to use a RecursiveReadonlyArray<> type that properly represents arrays with their methods like push(), and iterates into the array properly to propagate ReadOnly<>, as proven by the tests.

@spalger spalger added review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.0.0 v6.5.0 labels Sep 10, 2018
@spalger spalger changed the title [core/public/deepFreeze] fix recursive type to better support arrays [core/public/deepFreeze] fix recursive type for better array support Sep 10, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@spalger spalger merged commit 6ce4752 into elastic:master Sep 11, 2018
spalger pushed a commit to spalger/kibana that referenced this pull request Sep 11, 2018
…lastic#22904)

The `deepFreeze()` function used by `core.injectedMetadata` uses a recursive type definition to indicate that all of the child types within the passed argument become readonly, which works fine for objects but represents arrays as objects instead of using the `ReadonlyArray<>` type. 

This PR fixes the type definition to use a `RecursiveReadonlyArray<>` type that properly represents arrays with their methods like `push()`, and iterates into the array properly to propagate `ReadOnly<>`, as proven by the tests.
spalger pushed a commit that referenced this pull request Sep 11, 2018
…pport (#22904) (#22932)

Backports the following commits to 6.x:
 - [core/public/deepFreeze] fix recursive type for better array support  (#22904)
@spalger
Copy link
Contributor Author

spalger commented Sep 11, 2018

6.x/6.5: cfd2a8f

@spalger spalger deleted the fix/deep-freeze-types branch September 11, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v6.5.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants