Skip to content

[Bug]: Incorrect pluralization for custom service methods extended from MedusaService (type/actual function) #14328

@Neeptossss

Description

@Neeptossss

Package.json file

{
  "name": "",
  "version": "0.0.2",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "seed:categories": "medusa exec ./src/scripts/seed-categories.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "docker:up": "docker compose up --build -d",
    "docker:down": "docker compose down",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.11.3",
    "@medusajs/cli": "2.11.3",
    "@medusajs/framework": "2.11.3",
    "@medusajs/medusa": "2.11.3",
    "@react-email/components": "^0.0.36",
    "@react-email/preview": "0.0.12",
    "mssql": "^11.0.1",
    "nodemailer": "^6.10.0",
    "papaparse": "^5.5.2",
    "resend": "^4.2.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.11.3",
    "@swc/core": "1.7.28",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/nodemailer": "^6.4.17",
    "@types/papaparse": "^5.3.15",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.19.5

Database and its version

PostgreSQL 15

Operating system name and version

Docker

Browser name

No response

What happended?

When creating a module, we define its models and its service. The service extends MedusaService, which automatically generates basic CRUD methods such as list, create, etc.

In my case, I have a Company module with two models:

  • Company
  • CountryCompanyInfo

The module service is defined as follows:

import { Company } from "./models/company";
import { CountryCompanyInfo } from "./models/country_company_info";

class CompanyModuleService extends MedusaService({
  Company,
  CountryCompanyInfo,
}) {}

export default CompanyModuleService;

The base class MedusaService should generate basic CRUD methods for each model. Medusa pluralizes the method names automatically.

However, when TypeScript infers the method names from the model names, it generates the following method (using list as an example, but this applies to all CRUD methods):

companyModuleService.listCountryCompanyInfoes

This is incorrect.

The method listCountryCompanyInfoes does not exist at runtime and is not a valid function. The correct pluralized method name is:

companyModuleService.listCountryCompanyInfos

At runtime, the method works correctly with listCountryCompanyInfos, but the TypeScript types are wrong.

Image Image Image Image

Expected behavior

Correct pluralization of module service method types (e.g. CountryCompanyInfos instead of CountryCompanyInfoes).

Actual behavior

Incorrect pluralization in the generated TypeScript types for module service methods.

Link to reproduction repo

None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions