TypeScript: Exported types incomplete when using Prisma methods in TurboRepo

I’m encountering a TypeScript type inference issue in my TurboRepo setup, specifically when using Prisma methods within NestJS services. In the server package, I have an export.d.ts file that exports types for various controller methods and DTOs. However, TypeScript fails to infer complete types when using Prisma methods, resulting in incomplete type definitions when used in the frontend package.

Server Workspace:

// export.d.ts

import { AuthController } from './auth.controller';
import { SignInDto } from './auth.dto';

export * from './auth.controller';

// Partially exporting automatically typed return type
type Wrapper<T extends (...args: any) => any> = Awaited<ReturnType<T>>;

export namespace ApiTypes {
  export interface SignInPayload extends SignInDto {}
  export interface SignInResponse extends Wrapper<typeof AuthController.prototype.signin> { token: string }
}
// auth.service.ts

@Injectable()
export class AuthService {
  constructor(private prisma: PrismaClient) {}

  async signin(payload: SignInDto) {
    // Using Prisma method
    return await this.prisma.staffUsers.findUnique({
      where: { username: payload.identifier },
    });
  }
}

In the auth.service.ts file, TypeScript fails to infer the complete export return type of the signin method when using this.prisma.staffUsers.findUnique. While TypeScript correctly infers types when returning objects directly from the AuthService, it struggles with types inferred from Prisma methods. It works as expected the Server Workspace but does not infer complte when used inside the frontend workspace.

Example

// Returning hard object works fine even outside the server package.
// The types automatically inferred as Promise<{name:string;age:number}>
async signin(payload: SignInDto) {
  return { name: "Alice", age: 30 };
}



// But this does not work and infer type as Promise<any>
async signin(payload: SignInDto) {
  return await this.prisma.staffUsers.findUnique({
    where: { username: payload.identifier },
  });
}

Note that the issue is only encountered when using the export.d.types outside the server package e.g. inside the react frontend package but works as expected in server package itself.

I would really apreciate any solutions and please feel free to ask for any further explaination or resources related to the issue.

I have already tried defining return types explicitely into the sign method but I cant do that here because types returned from prisma are too complex and may become cumbersome to maintain in many scenarios.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật