Closed
Description
π Search Terms
- unable to infer this in setter
- ts2345
π Version & Regression Information
seems all version behavied the same
β― Playground Link
π» Code
type Entity = { id: string };
type RoleEntity = {
id: string;
};
class UserEntity {
id!: string;
role!: RoleEntity;
set roleId(id: string) {
setEntityRef(this, "role", id);
// ^ Argument of type 'string' is not assignable to parameter of type 'this[keyof this] extends Entity ? keyof this : never'.(2345)
setEntityRef(this as UserEntity, "role", id);
}
}
function setEntityRef<
T extends Entity,
K extends {
[P in keyof T]: T[P] extends Entity ? P : never;
}[keyof T]
>(owner: T, key: K, r: string) {}
π Actual behavior
this type is this instead of current.
π Expected behavior
works, can infer the fields
Additional information about the issue
No response