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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Update able to handle arrays #83

Closed
millsp opened this issue Dec 30, 2019 · 7 comments
Closed

Make Update able to handle arrays #83

millsp opened this issue Dec 30, 2019 · 7 comments
Labels
enhancement Improving something feature Add new features wontfix This will not be worked on

Comments

@millsp
Copy link
Owner

millsp commented Dec 30, 2019

馃崺 Feature Request

Is your feature request related to a problem?

Describe the solution you'd like

Describe alternatives you've considered

Teachability, Documentation, Adoption, Migration Strategy

@millsp
Copy link
Owner Author

millsp commented Dec 30, 2019

@mcpower If you have time to do this, otherwise I'll do this a bit later. When merging your last PRs, I did not find the time to transform Update to the latest standards.

@millsp millsp added enhancement Improving something feature Add new features labels Dec 30, 2019
@maroon1
Copy link

maroon1 commented Jan 6, 2020

Exciting, I am just searching a way to convert a instance array(tuple) to constructor type array(tuple).

@millsp
Copy link
Owner Author

millsp commented Jan 6, 2020

@maroon1 can you provide a full example of what you are trying to do?

@maroon1
Copy link

maroon1 commented Jan 6, 2020

// convert
type Constructors = [typeof ClassA, typeof ClassA, typeof ClassA];
// to
type InstanceTypes = [ClassA, ClassA, ClassA];

For example:

type MapToInstances<T> = { [K in keyof T]: InstanceType<T[K]>};  // it doesn't not work~

export class Transformer<T> {
  constructor(statics: T) {}

  transform(): MapToInstances<T>;
} 

const transfomer = new Transformer([ClassA, ClassA, ClassA]);
transformer.transform();  // [classA, classA, classA]

@millsp
Copy link
Owner Author

millsp commented Jan 6, 2020

You issue isn't related to this one:

For your problem, you needed to use Cast and as const:

import {A, C} from 'ts-toolbelt'

class ClassA {}

// convert
type Constructors = [typeof ClassA, typeof ClassA, typeof ClassA];
// to
type InstanceTypes = [ClassA, ClassA, ClassA];

type MapToInstances<T extends readonly C.Class[]> = {
    [K in keyof T]: C.InstanceOf<A.Cast<T[K], C.Class>>
};

export class Transformer<T extends readonly C.Class[]> {
    constructor(statics: T) {}

    transform(): MapToInstances<T> {
        return {} as any
    }
}

const transformer = new Transformer([ClassA, ClassA, ClassA] as const)
const transformed = transformer.transform() // [ClassA, ClassA, ClassA]

If you remove as const, your array will be narrowed to ClassA[]

If you have more questions, you're welcome to open an issue for it.

@stale
Copy link

stale bot commented Mar 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 6, 2020
@stale stale bot closed this as completed Mar 13, 2020
@millsp millsp reopened this Jul 9, 2020
@stale stale bot closed this as completed Jul 16, 2020
@millsp millsp reopened this Jul 16, 2020
@stale stale bot removed the wontfix This will not be worked on label Jul 16, 2020
@stale
Copy link

stale bot commented Sep 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Sep 14, 2020
@millsp millsp closed this as completed Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving something feature Add new features wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants