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

Helper functions for merging and selecting #123

Closed
heho opened this issue May 31, 2022 · 2 comments
Closed

Helper functions for merging and selecting #123

heho opened this issue May 31, 2022 · 2 comments

Comments

@heho
Copy link

heho commented May 31, 2022

It would be useful to have type safe helper functions for merging Record<Slots, string> or selecting several of those slots, I also found being able to rename slots quite helpful. Something along the lines of:

type ClassRecord = Record<Slots, string>

function mergeClassesDeep
    <C1 extends ClassRecord, C2 extends ClassRecord>
    (cf1: (() => C1) | undefined, cf2: ((() => C2)) | undefined): () => C1 & C2
    
function mergeClassesDeep
    <C1 extends ClassRecord, C2 extends ClassRecord, C3 extends ClassRecord>
    (cf1: (() => C1) | undefined, cf2: (() => C2) | undefined, cf3: (() => C3) | undefined): () => C1 & C2 & C3
    
//...

export function selectSlots
    <T extends ClassRecord, K1 extends keyof T>
    (record: T, key1: K1): Pick<T, K1>

export function selectSlots
    <T extends ClassRecord, K1 extends keyof T, K2 extends keyof T>
    (record: T, key1: K1, key2: K2): Pick<T, K1 | K2>
    
//...

export function renameSlots
    <T extends ClassRecord, K1 extends keyof T, R1 extends SlotType>
    (styleFunction: T, mapping1: [K1, R1]): Omit<T, K1> & ClassRecord<R1>

export function renameSlots
    <T extends ClassRecord, K1 extends keyof T, R1 extends SlotType, K2 extends keyof T, R2 extends SlotType>
    (record: T, mapping1: [K1, R1], mapping2: [K2, R2]): Omit<T, K1 | K2> & ClassRecord<R1 | R2>

I would much prefer if mapping was a Record, but I am not sure if it is possible to make that type safe.

@layershifter
Copy link
Member

Sorry but I did not get 🐱

Do need some help with your implementation? Or is it a feature request to add new functionality? If it's a feature request please explain what these functions do and in which scenarios they are useful.

@layershifter
Copy link
Member

Closing for housekeeping, but feel free to follow up.

@layershifter layershifter closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants