Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IngestManager] Move RequiredPackage type near DefaultPackages (#82188)
## Summary - [x] Move the `RequiredPackage` type to the same location as `DefaultPackages` so anyone looking at one will see the other as well - [x] New approach to defining & using enum-like values. ## The basic outline of the approach 1. Export a JS object `as const` from `common/constants/*` (expose runtime value) https://github.com/elastic/kibana/blob/d66cf601bb0466bd36254f40339ac41f9935436c/x-pack/plugins/ingest_manager/common/constants/epm.ts#L12-L15 1. Import that JS value and convert to a TS type as `type TSType = typeof jsValue` <img width="484" alt="Screen Shot 2020-11-02 at 2 12 27 PM" src="https://user-images.githubusercontent.com/57655/97910756-2e693700-1d18-11eb-9605-e33ceb64e857.png"> 1. The values (right-hand side) of that type can be converted to a union type with `ValueOf<X>` <img width="557" alt="Screen Shot 2020-11-02 at 3 10 22 PM" src="https://user-images.githubusercontent.com/57655/97914250-99693c80-1d1d-11eb-9605-92379aa4db38.png"> 1. The values can be accessed as TS types `TSType['key']` or JS `jsValue.key` This way we - still get the readability of TS `enum`s - can choose to only import the types of values we need (compile time or runtime) - use the TS utility types like `Pick`, `Omit`, etc ## More detail on 1 * Value which can be access/iterated at runtime, e.g. `Object.values(requiredPackages)` or `requiredPackages.System` * narrows the type those exact values, not `string` <img width="823" alt="Screen Shot 2020-11-02 at 2 15 58 PM" src="https://user-images.githubusercontent.com/57655/97910538-e0ecca00-1d17-11eb-9153-71171e9fba75.png"> * can't be modified (it's `readonly`) <img width="443" alt="Screen Shot 2020-11-02 at 2 12 09 PM" src="https://user-images.githubusercontent.com/57655/97910753-2dd0a080-1d18-11eb-82d4-3fe635ba3071.png">
- Loading branch information