whatsapp-api-js icon indicating copy to clipboard operation
whatsapp-api-js copied to clipboard

Types not working correctly unless module: "presserve"

Open muniter opened this issue 4 months ago • 3 comments

Describe the bug Typescript doesn't resolve types correctly unless my tsconfig uses module: Presserve To Reproduce Steps to reproduce the behavior:

  1. Use a tsconfig like this:
{
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,
    "verbatimModuleSyntax": true,
    "allowImportingTsExtensions": true,
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    /* The important option, with module: NodeNext it doesn't work, only with Presserve */
    "module": "NodeNext",
    "outDir": "dist",
    "sourceMap": true,
    "lib": ["es2022"]
  }
}
  1. Try the following code:
import type { OnMessageArgs } from "whatsapp-api-js/emitters";

const args = {} as OnMessageArgs;

args.message.type;
//            ^? any

The type of args.message.type is any.

  1. If we change the tsconfig compiler option module to Preserve the type is correctly resolved: text | audio | ...

Expected behavior Types should just work, the current tsconfig follows this recommendations

Desktop (please complete the following information):

  • OS: mac OS
  • Runtime: node 22
  • Library Version: 4.0.3, typescript 5.3.3

Additional context Add any other context about the problem here.

muniter avatar Sep 30 '24 18:09 muniter