Skip to content

After updating to 3.x.x getting TS2536  #28647

Closed
@pikax

Description

@pikax

TypeScript Version: typescript@3.3.0-dev.20181122

Search Terms:
TS2536 Record Map vuex

Code

interface ITest {
  expectedStr: string;
  expectedN: number;
}

interface MapAccessor<Getters> {
  <T = Getters, Map extends Record<string, keyof T> = Record<string, keyof T>>(
    map: Map
  ): { [K in keyof Map]: (() => T[Map[K]]) };
}

interface TestAccess {
  str: "expectedStr";
}

const t: MapAccessor<ITest> = {} as any;

const str = t({
  str: "expectedStr"
}).str;

Expected behavior:
No compile issue, is working using typescript@3.0.1, checked the breaking changes and found nothing in regards to this.

Intellisense still works as expected giving error if you change expectedStr to an invalid value.

Actual behavior:
Not giving error: index.ts:9:33 - error TS2536: Type 'Map[K]' cannot be used to index type 'T'.

Playground Link:
playground

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeWorking 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