openai / openai-node

Official JavaScript / TypeScript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.97k stars 870 forks source link

Missing break in switch statement at parser.ts line 184 #1067

Closed Karbashevskyi closed 2 months ago

Karbashevskyi commented 2 months ago

Confirm this is a Node library issue and not an underlying OpenAI API issue

Describe the bug

I encountered a TypeScript error (TS7029: Fallthrough case in switch) while working with the OpenAI Node.js client. The error is due to a missing break statement in the switch method at parser.ts line 184. Specifically, the case for 'number' does not have a break, causing a fallthrough to subsequent cases.

To Reproduce

  1. Install library: openai@4.60.0
  2. Use typescript: v5.5.4
  3. Run project

Code snippets

No response

OS

macOS

Node version

Node v20.11.1

Library version

openai v4.60.0

RobertCraigie commented 2 months ago

Thanks for the report, could you share your tsconfig.json?

Karbashevskyi commented 2 months ago
/* To learn more about this file see: https://angular.io/config/tsconfig. */ {
  "compileOnSave": false,
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ],
    "paths": {
      "@src/*": [
        "./src/*"
      ],
      "@environments/*": [
        "./src/environments/*"
      ],
      "@assets/*": [
        "./src/assets/*"
      ]
    },
    "plugins": [
      {
        "transform": "typia/lib/transform"
      }
    ],
    "strictNullChecks": true
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}
RobertCraigie commented 2 months ago

Thanks @Karbashevskyi! I can't reproduce the error you were seeing but we drastically changed how the partial json parser works in v4.61.0, please try it out and let me know if it's fixed now!

Karbashevskyi commented 2 months ago

@RobertCraigie this issue is not present in 4.61.0, I tried to run the project again with the 4.60.0 package to make sure it was only a problem with this version and it was indeed. Looks like you can close this issue. Thanks!