Skip to content

Can't use keyof index for indexing intersection of Partial<T> and another type in generic class<T>. #22286

Closed
@Griffork

Description

@Griffork

Bug
I'm trying to use an object's key to index an intersection into a partial of an object and another object, but I'm getting an error.
Note: this error only shows up in a generic class. Using plain types I was not able to replicate it.

TypeScript Version:
2.7.1-insiders.20180127 (playground)
2.3.1 (visual studio tools)
2.7.2 (command line)

Search Terms:
Keyof, intersection, union, Partial, index, merge.

Code

    interface Rum {
        "ho hum": string; 
    }

    interface Color {
        "blue": number;
    }

    class Thingy<T> {
        mything: Rum & Partial<T>;
        log(param: keyof T) {
            console.log(this.mything[param]); //ERROR!
        }
    }

Expected behavior:
No errors.

Actual behavior:
test.ts(13,25): error TS2536: Type 'keyof T' cannot be used to index type 'Rum & Partial'.

Playground link

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions