Skip to content

'keyof' constrained to intersection of type params ends up being constrained to 'never' #12624

Description

@DanielRosenwasser

For fun, I wanted to try to see how well TypeScript 2.1 could model Svelte's component API.

interface Options<Data, Computed> {
    data?: Data
    computed?: Computed;
}

declare class Component<Data, Computed> {
    constructor(options: Options<Data, Computed>);

    get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
}


let c = new Component({
    data: {
        hello: ""
    }
});

c.get("hello");
//    ~~~~~~~ error! '"hello"' is not assignable to type 'never'

Expected: No error.
Actual: The constaint of K on get appears to be 'never', and thus gives an error when calling c.get with any string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions