openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Getting more than a dozen errors in api.d.ts

Open microsoftbuild opened this issue 2 years ago • 3 comments

Describe the bug

Updated from v2.0.5 to 3.0.0 of the package and got 16 errors in node_modules/openai/dist/api.d.ts: [{ "resource": "PROJECT_PATH/node_modules/openai/dist/api.d.ts", "owner": "typescript", "code": "2304", "severity": 8, "message": "Cannot find name 'File'.", "source": "ts", "startLineNumber": 1666, "startColumn": 24, "endLineNumber": 1666, "endColumn": 24 }]

To Reproduce

Simply npm install openai on any typescript project.

Code snippets

"devDependencies": {
    "@types/glob": "^7.2.0",
    "@types/mocha": "^9.1.1",
    "@types/node": "14.x",
    "@types/vscode": "^1.67.0",
    "@typescript-eslint/eslint-plugin": "^5.21.0",
    "@typescript-eslint/parser": "^5.21.0",
    "@vscode/test-electron": "^2.1.3",
    "eslint": "^8.14.0",
    "glob": "^8.0.1",
    "mocha": "^9.2.2",
    "typescript": "^4.6.4"
  },
  "dependencies": {
    "openai": "^3.0.0"
  }

OS

macOS

Node version

Node v16.13.1

Library version

3.0.0

microsoftbuild avatar Nov 11 '22 04:11 microsoftbuild

I found that when you use

const { Configuration, OpenAIApi } = require("openai");

and not

import { Configuration, OpenAIApi } from 'openai';

The issue is resolved. I don't know why!

alexandre-hallaine avatar Dec 30 '22 22:12 alexandre-hallaine

Interesting. Given how import is preferred of require in TS.

microsoftbuild avatar Jan 02 '23 12:01 microsoftbuild

@execrate0 's recommendation worked to stop the errors, but fails to provide typesafety in the project.

jaimefps avatar Mar 28 '23 04:03 jaimefps

@execrate0 's recommendation worked to stop the errors, but fails to provide typesafety in the project.

Maybe Typescript is not really supported (or the latest versions)

alexandre-hallaine avatar Mar 28 '23 08:03 alexandre-hallaine

@execrate0 's recommendation worked to stop the errors, but fails to provide typesafety in the project.

Maybe Typescript is not really supported (or the latest versions)

Typescript checks work for me when using the import pattern; but the require pattern fails to infer types. I'll need to review if it's due to my setup or just the require pattern altogether.

jaimefps avatar Mar 28 '23 15:03 jaimefps

Our upcoming v4 has totally overhauled types, and should support import in addition to require. Please give it a try and share any feedback you may have in the thread.

rattrayalex avatar Jul 10 '23 01:07 rattrayalex