Best Practice for inference

Hi here is my problem:
type t_Prisma<MNs extends Record<string, string>> = {
ModelName: MNs
}
type t_Prisma<MNs extends Record<string, string>> = {
ModelName: MNs
}
class Prisma<P extends t_Prisma<MNs>, MNs extends Record<string, string>> implements t_Prisma<MNs> {
_prisma: P;

constructor(_prisma: P) {
this._prisma = _prisma;
}

get ModelName() {
return this._prisma.ModelName;
}
}
class Prisma<P extends t_Prisma<MNs>, MNs extends Record<string, string>> implements t_Prisma<MNs> {
_prisma: P;

constructor(_prisma: P) {
this._prisma = _prisma;
}

get ModelName() {
return this._prisma.ModelName;
}
}
vs
class Prisma<MNs extends Record<string, string>> implements t_Prisma<MNs> {
_prisma: t_Prisma<MNs>;

constructor(_prisma: t_Prisma<MNs>) {
this._prisma = _prisma;
}

get ModelName() {
return this._prisma.ModelName;
}
}
class Prisma<MNs extends Record<string, string>> implements t_Prisma<MNs> {
_prisma: t_Prisma<MNs>;

constructor(_prisma: t_Prisma<MNs>) {
this._prisma = _prisma;
}

get ModelName() {
return this._prisma.ModelName;
}
}
In the first code, the inference for ModelName doesn't work as expected, but it feels more natural. In the second code, the inference works fine, but it forces me to repeat the type P everywhere, which is not ideal. Thank you for reading
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?