Skip to content

4.4 index signature check on wrong generic? #45548

Closed
@zmagyar

Description

@zmagyar

Bug Report

We are using key remapping with template strings to type getters/setters generated automatically for our classes as can be seen in the simplified code below. This worked nicely in 4.3 and provided typing for getA() and getB() functions,
Using 4.4 it is still working but we are getting errors when any class member is named as 'getXXX'.

export interface AssociationConfig<U extends string> {
    [propName: string]: U;
};

export type AutoGeneratedFunctions<T extends AssociationConfig<string>> = {
        [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]
    } 
  
interface FooAssociations extends AssociationConfig<string> {
    a: 'aaaa',
    b: 'bbbb'
}

interface Foo extends AutoGeneratedFunctions<FooAssociations> {

}

class Foo {
    doSome(a: number): string {
        return 'this works';
    }
    getSome(): string {
        return 'this works';
    }
    getSomethigElse(a: number): string {
        return "this fails: Property getSomethigElse' of type '(a: number) => string' is not assignable to '`get${string}`' index type '() => string' ";
    }
}
Output
;
class Foo {
    doSome(a) {
        return 'this works';
    }
    getSome() {
        return 'this works';
    }
    getSomethigElse(a) {
        return "this fails: Property getSomethigElse' of type '(a: number) => string' is not assignable to '`get${string}`' index type '() => string' ";
    }
}
export {};
Compiler Options
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

🔎 Search Terms

key remapping, template strings, 4.4

🕗 Version & Regression Information

This changed between versions 4.3 and 4.4

🙁 Actual behavior

The Foo class can not have any member starting with get which doesn't match the signature defined in AutoGeneratedFunctions

🙂 Expected behavior

The signature defined in AutoGeneratedFunctions should only be applied to getA() and getB() functions because only those are defined in FooAssociations.

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