Skip to content

Mapped type beyond one level simplification problem with Partial and Record. #29752

Closed
@bowenni

Description

@bowenni

TypeScript Version: 3.4.0-dev.20190202

Search Terms:
Record, Partial

Code

function f<K extends string, V, T extends Partial<Record<K, V[]>>>(
    object: T,
    key: K,
    value: V[],
) {
  object[key] = value;
}

Expected behavior:
No errors.

Actual behavior:
index.ts:6:3 - error TS2322: Type 'V[]' is not assignable to type 'T[K]'.

Playground Link:
https://www.typescriptlang.org/play/#src=function%20f%3CK%20extends%20string%2C%20V%2C%20T%20extends%20Partial%3CRecord%3CK%2C%20V%5B%5D%3E%3E%3E(%0D%0A%20%20%20%20object%3A%20T%2C%0D%0A%20%20%20%20key%3A%20K%2C%0D%0A%20%20%20%20value%3A%20V%5B%5D%2C%0D%0A)%20%7B%0D%0A%20%20object%5Bkey%5D%20%3D%20value%3B%0D%0A%7D
Enabling all strictness flags still gives me the same error.

Related Issues:
I think this is a duplicate of #28839, which is marked as fixed. I asked for reopen in #28839 (comment) but got no rely. I'm assuming that closed issues are not on your radar so opening a new issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions