Skip to content

Convert to ESModules & export everything#20

Open
NatoBoram wants to merge 8 commits into
hmarr:mainfrom
coderabbitai:bugfix/to-esmodule
Open

Convert to ESModules & export everything#20
NatoBoram wants to merge 8 commits into
hmarr:mainfrom
coderabbitai:bugfix/to-esmodule

Conversation

@NatoBoram
Copy link
Copy Markdown

@NatoBoram NatoBoram commented Mar 18, 2024

Hi!

While using this package, I needed to import some private types. There were also some imports that were very tricky to use, so I moved the package to ESModules for better compatibility. I also encountered an issue while using Jest; it seems like it's severely outdated as its ESModule support is experimental. Switching to Vitest made it work without having a config file.

With this change, instead of:

import type {
	FunctionDef,
	ObjectProp, // Module '"openai-chat-tokens/dist/functions.js"' declares 'ObjectProp' locally, but it is not exported.
} from "openai-chat-tokens/dist/functions.js"

It's now:

import type { FunctionDef, ObjectProp } from "openai-chat-tokens"

@hellohejinyu
Copy link
Copy Markdown

import { functionsTokensEstimate } from 'openai-chat-tokens';

type FunctionDef = Parameters<typeof functionsTokensEstimate>[0][number];
type ObjectProp = FunctionDef['parameters'];

Maybe you can try like this.

@NatoBoram
Copy link
Copy Markdown
Author

Yeah, that's true. I ended up re-publishing the package under https://github.com/coderabbitai/openai-chat-tokens to avoid dealing with more type aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants