-
Notifications
You must be signed in to change notification settings - Fork 12.8k
4.4 index signature check on wrong generic? #45548
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
Comments
One of the issues here is that the key remapping also applies to the index signature in export interface AssociationConfig<U extends string> {
[propName: string]: U;
}; so you end up creating a template index signature in the subclass. I don't think this was a situation that we had anticipated but I believe that the behavior is "expected". Tagging @ahejlsberg to get his take on this as well though. It seems like the root issue is that index signatures are often also used as a "constraint" on all the properties in a class; but there's no way to say "I want all my properties to conform to |
could be done by #7481 |
Well only for an expression - there's no way to ensure a type satisfies another type without unused local type aliases and the like (e.g. |
The specific change in 4.4 is that we now generate index signatures in mapped types for keys that are template literal strings with placeholders. See #44512 for more details. In this particular example, the string index signature introduced by It's pretty easy to get the old behavior by excluding string index signatures in export type AutoGeneratedFunctions<T extends AssociationConfig<string>> = {
[K in keyof T as string extends K ? never : `get${Capitalize<string & K>}`]: () => T[K]
} |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
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'.
Output
Compiler Options
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 withget
which doesn't match the signature defined inAutoGeneratedFunctions
🙂 Expected behavior
The signature defined in
AutoGeneratedFunctions
should only be applied togetA()
andgetB()
functions because only those are defined inFooAssociations
.The text was updated successfully, but these errors were encountered: