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

Union of generic indexed types works incorrectly #26608

Closed
IIIristraM opened this issue Aug 22, 2018 · 1 comment · Fixed by #26281
Closed

Union of generic indexed types works incorrectly #26608

IIIristraM opened this issue Aug 22, 2018 · 1 comment · Fixed by #26281
Assignees
Labels
Bug A bug in TypeScript

Comments

@IIIristraM
Copy link

I have two generic indexed types

type ExtendedService<T> = {
    [K in keyof T]: T[K] & {
        __$daemonMode?: string;
        __$action?: string;
    };
};

type Service<T> = {
    [K in keyof T]: T[K] & {id?: string};
};

And use them like this

export const createService = <T>(
    ServiceCtr: ExtendedService<T> & Service<T>
) => {
    ...
    Object.keys(ServiceCtr).forEach(key => {
        const method = (ServiceCtr)[key as keyof T];
        const {__$daemonMode, __$action, id} = method;
        ...
    }
}

VS Code output for method type is

const method: ({ [K in keyof T]: T[K] & {
    __$daemonMode?: string;
    __$action?: string;
}; } & Service<T>)[keyof T]

Expected behavior:

properties __$daemonMode, __$action, id exists on method variable;
const {__$daemonMode, __$action, id} = method; has no errors;

Actual behavior:

I got an error

[ts] Type '(ExtendedService<T> & Service<T>)[keyof T]' has no property '__$daemonMode' and no string index signature.

__$action and id produces the same error;

P.S.

Expression

const x: (ExtendedService<{z: {}}> & Service<{z: {}}>)['z'];
const {__$daemonMode, __$action, id} = x;

works as expected

@RyanCavanaugh
Copy link
Member

Fixed by #26281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants