openai-node
openai-node copied to clipboard
Getting more than a dozen errors in api.d.ts
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
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!
Interesting. Given how import is preferred of require in TS.
@execrate0 's recommendation worked to stop the errors, but fails to provide typesafety in the project.
@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)
@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.
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.