Skip to content

Intersection type with partial not working #16251

Closed
@jvanbruegge

Description

@jvanbruegge

TypeScript Version: 2.2.1

Code

export type Transformer<Si> = (name: string) => (s: Array<Instances<Si>>) => Array<any>;
export type TransformerConfig<Si> = { [k in keyof Si]?: Transformer<Si> };
//export type TransformerConfig<Si> = Partial<{ [k in keyof Si]: Transformer<Si> }>; <-- same result
export type ToSinksConfig<Si> = { '*': Transformer<Si> } & TransformerConfig<Si>;
//export type ToSinksConfig<Si> = { '*': Transformer<Si> } & TransformerConfig<Si> | { '*': Transformer<Si> }; <-- works
export type Instances<Si> = { ins: Array<Si> };

class Configurator<Si> {
    public configure(config: ToSinksConfig<Si> = { '*': n => x => x }): any {
        return undefined;
    }
}

Expected behavior:
No errors

Actual behavior:

test.ts(7,22): error TS2322: Type '{ '*': (n: string) => (x: Instances<Si>[]) => Instances<Si>[]; }' is not assignable to type 'ToSinksConfig<Si>'.
  Type '{ '*': (n: string) => (x: Instances<Si>[]) => Instances<Si>[]; }' is not assignable to type 'TransformerConfig<Si>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions