Skip to content

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

Merged
spalger merged 1 commit intoelastic:masterfrom
spalger:fix/deep-freeze-types
Sep 11, 2018
Merged

[core/public/deepFreeze] fix recursive type for better array support#22904
spalger merged 1 commit intoelastic:masterfrom
spalger:fix/deep-freeze-types

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 Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// 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

@spalger spalger requested a review from azasypkin September 11, 2018 14:25
Copy link
Contributor

@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 Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v6.5.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments