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

Filter keyof properties by types #13214

Closed
asfernandes opened this issue Dec 29, 2016 · 2 comments
Closed

Filter keyof properties by types #13214

asfernandes opened this issue Dec 29, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@asfernandes
Copy link

asfernandes commented Dec 29, 2016

So there is:

type Deferred<T> = {
    [P in keyof T]: Promise<T[P]>;
};

And we have:

interface Obj
{
    id: number;

    employee: {
        id: number;
        name: string;
    }

    // an array here too
}

With Deferred<Obj> the employee object and arrays will also be Promise but that would not always be what we want. It also will not nest on children objects.

The ability to filter keys by type would be very good as:

type Container<T> = {
    [P in keyof T where T[P] extends number | string]: Promise<T[P]>;
    [P in keyof T where T[P] extends {}]: Container<T[P]>;
}

If use more than one in would be out of question, something using intersection may work too.

@ahejlsberg
Copy link
Member

Yes, this would be a nice capability to have. I think it is already covered by #12424.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Dec 29, 2016
@mhegazy mhegazy closed this as completed Dec 29, 2016
@asfernandes
Copy link
Author

I understand the similarity and depending on the design of #12424 it will cover my needs. On the other hand, this issue may do additional things, i.e., really "filter" out (hide) what comes from in/keyof depending on a condition.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants