PickFirst for Union Type or ForEach(Union Item) or spread infer for Union Types #44116
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Suggestion
I would like to suggest a PickFirst for union Types which will return the first element in the union, which would allow for incremental processing of items in more advance ways. Typically current one can process arrays using type inference.
Such as the following Array Items extends [infer A, ... infer ArrayRemderItems] , one is able to process array items incrementally and can produce and accumulate string type. This is typically the only operator that I think is still missing in which would allow on to manipulated all structures and forms to different types, with no issues. Alternative is simpler one should be less over head ForEach operator. Sure there are many different ways one could look at implementing this, at the moment just limited in all 3 options I can think of.
🔍 Search Terms
ForEach keyof, UnionTypes, Accumulator.
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
📃 Motivating Example
Basically allows on to full re-write types and not just allow there nested depth to be re-written, which full opens up the doors to
collapsing type into one, especially with string literal types manipulators now. Evalute many different forms for MQTT and brokers and things even will be able to do populate and deep populdate properly and anything old dot seperate javascripts methiods.
First approach improve processing of Union types for grouping at top level.
Alternative, would be for a ForEach, with or with out an accumulator. The concept below.
Full ability to capture information and transform it one two axis nested depth and breath of keys can be accumulated into more complex compound structures
💻 Use Cases
Improve more complex string validation and handing of more complex operations with paths and pathWithParams and QueryParams in a Request and deepPopulate and populate, where one is require to capture if parameter is query param
query(paths) // query( 'mainPath' | '${param1}' | '/' | '${param2}/?Query1=',
Other approach is just to use nested object {path:'section',param:{name:'param1':path:....
Further use cases, which allow one ideally to work from datasource to api enpoint across into frontend and back, with out retyping a thing. Ideally one want one validation program that runs database, body, response, and frontend. So only way is really reflection and decorators. Sadly interfaces can't have decorators, so have to use a class with a typecheck that can only use vanilla properties, but can't write a type constraint for class to be data only classes. :-( So we still not there yet.
https://github.com/wesleyolis/mongooseRelationalTypes
The text was updated successfully, but these errors were encountered: