Skip to content

Union of generic indexed types works incorrectly #26608

Description

I have two generic indexed types

typeExtendedService<T>={[KinkeyofT]: T[K]&{__$daemonMode?: string;__$action?: string;};};typeService<T>={[KinkeyofT]: T[K]&{id?: string};};

And use them like this

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

VS Code output for method type is

constmethod: ({[KinkeyofT]: T[K]&{__$daemonMode?: string;__$action?: string;};}&Service<T>)[keyofT]

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

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

works as expected

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions