Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'string' cannot be used to index type 'T' - after upgrade from 3.4 to 3.5 #32704

Closed
FrancescoBorzi opened this issue Aug 4, 2019 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@FrancescoBorzi
Copy link

FrancescoBorzi commented Aug 4, 2019

TypeScript Version: 3.6.0-dev.20190804 as well as 3.5.3. It was fine in version 3.4.5

Code

Here's a minimal reproduction tested using tsc:

class ParentType {
  [key: string]: string|number;
}

class ChildType extends ParentType {
  someKey: number;
}

class MyClass<T extends ParentType> {
  field: T;

  doStuff() {
    this.field['someKey'] = 123;
  }
}

error TS2536: Type 'string' cannot be used to index type 'T'.

Expected behavior:

There shouldn't be breaking changes from one minor version to another

Actual behavior:

Upgrading my app from 3.4.5 to 3.5.3 caused a build error

Real code: azerothcore/Keira3#12

@jack-williams
Copy link
Collaborator

Changed by #30769. Specifically see:

Given a type variable T with a constraint C, when an indexed access T[K] occurs on the target side of a type relationship, index signatures in C are now ignored. This is because a type argument for T isn't actually required to have an index signature, it is just required to have properties with matching types.

@FrancescoBorzi
Copy link
Author

then shouldn't the major version be updated? e.g. 4.0

@jack-williams
Copy link
Collaborator

#14116

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 5, 2019
@FrancescoBorzi
Copy link
Author

if this is an intended change, how am I supposed to change my code to comply with the new version?

also @RyanCavanaugh what is the duplicating issue?

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants